SlideShare a Scribd company logo
Finagle and Java Service Framework
@pavan
#service-framework
● Finagle Overview
● Programming with Futures
● Java Service Framework
Agenda
● Asynchronous, protocol-agnostic RPC framework for JVM languages
● Provides async client/server abstractions and hides low-level network details
of Netty
● Out of the box support for protocols such as HTTP, Thrift, Redis, Memcached
but can be extended
● Implemented in Scala
● Open-sourced by Twitter
Part 1. What is Finagle?
Blocking/Non-blocking/Asynchronous APIs
Blocking:
read(fd, …) // Thread is blocked until some data is available to read
Non Blocking:
read(fd, …) // Returns immediately either with data or EAGAIN
Asynchronous:
read(fd, callback(data),...)
Finagle Architecture
Netty:
Event-based
Low-level network I/O
Finagle:
Service-oriented,
Functional abstractions
[3] Thanks @vkostyukov for the diagram
Server Modules
● Servers are simple and optimized for high-throughput
Client Modules
Clients are tricky and have with the bulk of fault-tolerance logic. By default, they
are optimized for high success rate and low latency.
● Designed for handling workloads that have a mix of Compute and I/O.
● Each server can handle thousands of requests.
● Uses just two threads per core (Netty’s default, but its configurable).
How does it scale?
Programming with Futures
Part 2. Programming with Futures
● What is a Future?
○ A container to hold the value of async computation that may be either a
success or failure.
● History - Introduced as part of Java 1.5 java.util.concurrent.Future but had
limited functionality: isDone() and get() [blocking]
● Twitter Futures - Are more powerful and adds composability!
● Part of util-core package and not tied to any thread pool model.
Futures - continued
It’s a simple state machine
Pending
Failed
Succeeded
Done
How to consume Futures?
● Someone gives you a future, you act on it and pass it on (kinda hot potato)
Typical actions:
● Transform the value [map(), handle()]
● Log it, update stats [side-effect/callbacks - onSuccess(), onFailure()]
● Trigger another async computation and return that result [flatmap(), rescue()]
Most of the handlers are variations of the basic handler transform()
Future<B> transform(Function<Try<A>, Future<B>>);
Example 1
The backend I am calling returns an int, but I need to return a
string to my caller. What do I use?
Example 1
The backend I am calling returns an int, but I need to return a
string to my caller. What do I use?
Answer: map!
public Future<String> foo() {
return backend.foo().map(new Function<Integer, String>() {
public String apply(Integer i) {
return i.toString();
}
});
}
Example 1
The backend I am calling returns an int, but I need to return a
string to my caller. What do I use?
Answer: map!
import static com.twitter.util.Function.func;
public Future<String> foo() {
return backend.foo().map(func(i -> i.toString()));
}
Example 2
I consult a cache for a value, but on a miss, need to talk to a
database. What do I use?
Example 2
I consult a cache for a value, but on a miss, need to talk to a
database. What do I use?
Answer: flatmap!
public Future<Value> fetch(Key k) {
return cache.fetch(k).flatmap(
new Function<Value, Future<Value>>() {
public Future<Value> apply(Value v) {
if (v != null) return Future.value(v);
return db.fetch(k);
}
});
}
Handling Exceptions
● Don’t forget: map/flatmap will only execute for successful
futures
● To deal with exceptions: handle/rescue are the analogous
equivalent
Future<A> handle(Function<Throwable, A>)
Future<A> rescue(Function<Throwable, Future<A>>)
Example 1
If the backend I am calling throws an exception, I want to return
an error code. What do I use?
Example 1
If the backend I am calling throws an exception, I want to return
an error code. What do I use?
Answer: handle!
public Future<Result> foo() {
return backend.foo().handle(
new Function<Throwable, Result>() {
public Result apply(Throwable t) {
Result r = new Result();
r.setErrorCode(errorCodeFromThrowable(t));
return r;
}
});
Example 2
I consult a cache for a value, but if that failed, need to talk to a
database. What do I use?
Example 2
I consult a cache for a value, but if that failed, need to talk to a
database. What do I use?
Answer: rescue!
public Future<Value> get(Key k) {
return cache.fetch(k).rescue(
new Function<Throwable, Future<Value>>() {
public Future<Value> apply(Throwable t) {
LOG.error(“Cache lookup failed”, t);
return db.fetch(k)
}
});
}
Other handlers
More Sequential composition - join()
Concurrent composition, return after all are satisfied - collect()
Concurrent composition, return if any of the future is satisfied - select()
Finish within in a Timeout: within()
Delayed execuion: delayed()
Common Pitfalls
● Never block on a Future in production code (ok for unit tests)
○ Avoid future.get(), future.apply(), Await.result(future) as it ties up I/O processing threads and
it degrades Finagle’s performance considerably.
○ If you really need to block because you are dealing with synchronous libraries such as jdbc,
jedis use a dedicated FuturePool.
● Avoid ThreadLocal<T>. Use com.twitter.finagle.context.LocalContext instead
● Don't use parallel streams in Java 8
● Request concurrency leak - Never return “null” instead of Future<A>
Future<String> getPinJson(long pinId) {
return null; // This is bad!
// Use, return Future.value(null);
}
Part 3. Java Service Framework Features
Standardized Metrics - per client, per method success/fail counts and latency stats
Logging - slow log, exception log,
Rate limiting - Enforce quotas for clients
Genesis - Tool to generate the required stubs to bootstrap a finagle-thrift service
Warm up hook
Graceful shutdown
You need to enable your options via Proxy builder
ServiceFrameworkProxy<UserService.ServiceIface> serviceFrameworkProxy =
new ServiceFrameworkProxyBuilder<UserService.ServiceIface>()
.setHandler(serviceHandler)
.setServiceName(serviceName)
.setClusterName(serviceName.toLowerCase())
.setServerSetPath(serverSetPath)
.setClientNameProvider(new DefaultClientNameProvider())
.setRootLog(LOG)
.setFailureLog(FAILURE_LOG)
.enableExceptionTypeForFailureCount()
.disableLoggingForThrowable(ClientDiscardedRequestException.class)
.disableThrowablesAsServiceFailure(
Arrays.asList(ClientDiscardedRequestException.class,
DataValidationException.class))
.enableMethodNameForSuccessCountV2()
.enableMethodNameForFailureCountV2()
.enableMethodNameForResponseTimeMetricsV2()
.enableClientNameTagForSuccessCount()
.enableClientNameTagForFailureCount()
.enableClientNameTagForResponseTimeMetrics()
.enableExceptionLog()
.build();
Complaint 1:
● Clients are noticing higher latency or timeouts during deploys or restarts.
First few requests take longer than at steady state due to connection
establishment, Java’s Hopspot JIT etc.
Solution: Use warmUp hook and then join serverset
public static boolean warmUp(Callable<Boolean> warmUpCall)
// By default, invokes warmUpCall 100 times concurrently and expects it succeeds for at least 80%
of the calls
Graceful Shutdown
● Unjoin from serverset, waits for duration/2 secs and then tries to gracefully
shutdown server by draining existing requests within the remaining duration/2
secs
ServiceShutdownHook.register(server, Duration.fromSeconds(10), status)
public static void register(final Server server, final Duration gracePeriod,
final ServerSet.EndpointStatus endpointStatus)
Complaint 2:
Client is seeing rate limiting Exceptions even though rate limits are set to a high
value
Happens if the the server cluster is huge and the local rate limit per node becomes
small and the python client is running on few nodes (pinlater, offline job etc)
Solution: Try reducing max_connection_lifespan_ms if its python thriftmux client
Next steps
● Finagle upgrade to 6.43
○ Unlocks Retry Budgets
○ Defaults to P2C Load balancer instead of heap
○ Toggle between Netty3 and Netty4
○ Couple of performance fixes in Future scheduler
○ Many more...
Resources:
“Your server as a function” paper - https://dl.acm.org/citation.cfm?id=2525538
Source code: https://github.com/twitter/finagle
Finaglers - https://groups.google.com/d/forum/finaglers
Blogs:
[1] https://twitter.github.io/scala_school/finagle.html
[2] https://twitter.github.io/finagle/guide/developers/Futures.html
[3] http://vkostyukov.net/posts/finagle-101/
Thank you!

More Related Content

What's hot (20)

PDF
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
PPTX
Java script advance-auroskills (2)
BoneyGawande
 
DOC
Ad java prac sol set
Iram Ramrajkar
 
PPTX
Java script – basic auroskills (2)
BoneyGawande
 
PPTX
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
PDF
Creating Lazy stream in CSharp
Dhaval Dalal
 
PDF
Advanced Java Practical File
Soumya Behera
 
PPT
Swiss army knife Spring
Mario Fusco
 
PDF
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
PDF
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 
DOC
Advanced Java - Praticals
Fahad Shaikh
 
PPTX
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
PDF
Pragmatic functional refactoring with java 8
RichardWarburton
 
PDF
Proxy Deep Dive JUG Saxony Day 2015-10-02
Sven Ruppert
 
PPTX
Introduction to nsubstitute
Suresh Loganatha
 
PPTX
Java script
Dhananjay Kumar
 
PDF
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
PDF
Monads in Swift
Vincent Pradeilles
 
PDF
How to implement g rpc services in nodejs
Katy Slemon
 
PDF
C++aptitude questions and answers
sheibansari
 
Reactive Programming for a demanding world: building event-driven and respons...
Mario Fusco
 
Java script advance-auroskills (2)
BoneyGawande
 
Ad java prac sol set
Iram Ramrajkar
 
Java script – basic auroskills (2)
BoneyGawande
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Creating Lazy stream in CSharp
Dhaval Dalal
 
Advanced Java Practical File
Soumya Behera
 
Swiss army knife Spring
Mario Fusco
 
OSCON - ES6 metaprogramming unleashed
Javier Arias Losada
 
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco
 
Advanced Java - Praticals
Fahad Shaikh
 
LinkedIn TBC JavaScript 100: Functions
Adam Crabtree
 
Pragmatic functional refactoring with java 8
RichardWarburton
 
Proxy Deep Dive JUG Saxony Day 2015-10-02
Sven Ruppert
 
Introduction to nsubstitute
Suresh Loganatha
 
Java script
Dhananjay Kumar
 
Refactoring to Java 8 (Devoxx BE)
Trisha Gee
 
Monads in Swift
Vincent Pradeilles
 
How to implement g rpc services in nodejs
Katy Slemon
 
C++aptitude questions and answers
sheibansari
 

Similar to Finagle and Java Service Framework at Pinterest (20)

PPTX
Exploring Twitter's Finagle technology stack for microservices
💡 Tomasz Kogut
 
PDF
Twitter Finagle
Knoldus Inc.
 
PDF
The Future starts with a Promise
Alexandru Nedelcu
 
PDF
Async Microservices with Twitter's Finagle
Vladimir Kostyukov
 
PDF
Julio Capote, Twitter
Ontico
 
PDF
Scala.io
Steve Gury
 
PDF
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Michaël Figuière
 
PDF
Scala(finagle)@SmartNews_English
Shigekazu Takei
 
PDF
Writing Asynchronous Programs with Scala & Akka
Yardena Meymann
 
PDF
Reactive mistakes - ScalaDays Chicago 2017
Petr Zapletal
 
PPTX
Composable Futures with Akka 2.0
Mike Slinn
 
PDF
Java one2013
Aleksei Kornev
 
PPT
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
PDF
Expect the unexpected: Prepare for failures in microservices
Bhakti Mehta
 
PDF
Principles of the Play framework
Bernhard Huemer
 
PPTX
Finagle Lightning Talk JPR 2014
Chris Phelps
 
PDF
Using Akka Futures
Knoldus Inc.
 
PDF
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
PDF
Advanced patterns in asynchronous programming
Michael Arenzon
 
PDF
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Chris Richardson
 
Exploring Twitter's Finagle technology stack for microservices
💡 Tomasz Kogut
 
Twitter Finagle
Knoldus Inc.
 
The Future starts with a Promise
Alexandru Nedelcu
 
Async Microservices with Twitter's Finagle
Vladimir Kostyukov
 
Julio Capote, Twitter
Ontico
 
Scala.io
Steve Gury
 
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Michaël Figuière
 
Scala(finagle)@SmartNews_English
Shigekazu Takei
 
Writing Asynchronous Programs with Scala & Akka
Yardena Meymann
 
Reactive mistakes - ScalaDays Chicago 2017
Petr Zapletal
 
Composable Futures with Akka 2.0
Mike Slinn
 
Java one2013
Aleksei Kornev
 
Distributed & Highly Available server applications in Java and Scala
Max Alexejev
 
Expect the unexpected: Prepare for failures in microservices
Bhakti Mehta
 
Principles of the Play framework
Bernhard Huemer
 
Finagle Lightning Talk JPR 2014
Chris Phelps
 
Using Akka Futures
Knoldus Inc.
 
Play Framework: async I/O with Java and Scala
Yevgeniy Brikman
 
Advanced patterns in asynchronous programming
Michael Arenzon
 
Consuming web services asynchronously with Futures and Rx Observables (svcc, ...
Chris Richardson
 
Ad

Recently uploaded (20)

PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Tally software_Introduction_Presentation
AditiBansal54083
 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
SAP Firmaya İade ABAB Kodları - ABAB ile yazılmıl hazır kod örneği
Salih Küçük
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
Ad

Finagle and Java Service Framework at Pinterest

  • 1. Finagle and Java Service Framework @pavan #service-framework
  • 2. ● Finagle Overview ● Programming with Futures ● Java Service Framework Agenda
  • 3. ● Asynchronous, protocol-agnostic RPC framework for JVM languages ● Provides async client/server abstractions and hides low-level network details of Netty ● Out of the box support for protocols such as HTTP, Thrift, Redis, Memcached but can be extended ● Implemented in Scala ● Open-sourced by Twitter Part 1. What is Finagle?
  • 4. Blocking/Non-blocking/Asynchronous APIs Blocking: read(fd, …) // Thread is blocked until some data is available to read Non Blocking: read(fd, …) // Returns immediately either with data or EAGAIN Asynchronous: read(fd, callback(data),...)
  • 5. Finagle Architecture Netty: Event-based Low-level network I/O Finagle: Service-oriented, Functional abstractions [3] Thanks @vkostyukov for the diagram
  • 6. Server Modules ● Servers are simple and optimized for high-throughput
  • 7. Client Modules Clients are tricky and have with the bulk of fault-tolerance logic. By default, they are optimized for high success rate and low latency.
  • 8. ● Designed for handling workloads that have a mix of Compute and I/O. ● Each server can handle thousands of requests. ● Uses just two threads per core (Netty’s default, but its configurable). How does it scale?
  • 10. Part 2. Programming with Futures ● What is a Future? ○ A container to hold the value of async computation that may be either a success or failure. ● History - Introduced as part of Java 1.5 java.util.concurrent.Future but had limited functionality: isDone() and get() [blocking] ● Twitter Futures - Are more powerful and adds composability! ● Part of util-core package and not tied to any thread pool model.
  • 11. Futures - continued It’s a simple state machine Pending Failed Succeeded Done
  • 12. How to consume Futures? ● Someone gives you a future, you act on it and pass it on (kinda hot potato) Typical actions: ● Transform the value [map(), handle()] ● Log it, update stats [side-effect/callbacks - onSuccess(), onFailure()] ● Trigger another async computation and return that result [flatmap(), rescue()] Most of the handlers are variations of the basic handler transform() Future<B> transform(Function<Try<A>, Future<B>>);
  • 13. Example 1 The backend I am calling returns an int, but I need to return a string to my caller. What do I use?
  • 14. Example 1 The backend I am calling returns an int, but I need to return a string to my caller. What do I use? Answer: map! public Future<String> foo() { return backend.foo().map(new Function<Integer, String>() { public String apply(Integer i) { return i.toString(); } }); }
  • 15. Example 1 The backend I am calling returns an int, but I need to return a string to my caller. What do I use? Answer: map! import static com.twitter.util.Function.func; public Future<String> foo() { return backend.foo().map(func(i -> i.toString())); }
  • 16. Example 2 I consult a cache for a value, but on a miss, need to talk to a database. What do I use?
  • 17. Example 2 I consult a cache for a value, but on a miss, need to talk to a database. What do I use? Answer: flatmap! public Future<Value> fetch(Key k) { return cache.fetch(k).flatmap( new Function<Value, Future<Value>>() { public Future<Value> apply(Value v) { if (v != null) return Future.value(v); return db.fetch(k); } }); }
  • 18. Handling Exceptions ● Don’t forget: map/flatmap will only execute for successful futures ● To deal with exceptions: handle/rescue are the analogous equivalent Future<A> handle(Function<Throwable, A>) Future<A> rescue(Function<Throwable, Future<A>>)
  • 19. Example 1 If the backend I am calling throws an exception, I want to return an error code. What do I use?
  • 20. Example 1 If the backend I am calling throws an exception, I want to return an error code. What do I use? Answer: handle! public Future<Result> foo() { return backend.foo().handle( new Function<Throwable, Result>() { public Result apply(Throwable t) { Result r = new Result(); r.setErrorCode(errorCodeFromThrowable(t)); return r; } });
  • 21. Example 2 I consult a cache for a value, but if that failed, need to talk to a database. What do I use?
  • 22. Example 2 I consult a cache for a value, but if that failed, need to talk to a database. What do I use? Answer: rescue! public Future<Value> get(Key k) { return cache.fetch(k).rescue( new Function<Throwable, Future<Value>>() { public Future<Value> apply(Throwable t) { LOG.error(“Cache lookup failed”, t); return db.fetch(k) } }); }
  • 23. Other handlers More Sequential composition - join() Concurrent composition, return after all are satisfied - collect() Concurrent composition, return if any of the future is satisfied - select() Finish within in a Timeout: within() Delayed execuion: delayed()
  • 24. Common Pitfalls ● Never block on a Future in production code (ok for unit tests) ○ Avoid future.get(), future.apply(), Await.result(future) as it ties up I/O processing threads and it degrades Finagle’s performance considerably. ○ If you really need to block because you are dealing with synchronous libraries such as jdbc, jedis use a dedicated FuturePool. ● Avoid ThreadLocal<T>. Use com.twitter.finagle.context.LocalContext instead ● Don't use parallel streams in Java 8 ● Request concurrency leak - Never return “null” instead of Future<A> Future<String> getPinJson(long pinId) { return null; // This is bad! // Use, return Future.value(null); }
  • 25. Part 3. Java Service Framework Features Standardized Metrics - per client, per method success/fail counts and latency stats Logging - slow log, exception log, Rate limiting - Enforce quotas for clients Genesis - Tool to generate the required stubs to bootstrap a finagle-thrift service Warm up hook Graceful shutdown
  • 26. You need to enable your options via Proxy builder ServiceFrameworkProxy<UserService.ServiceIface> serviceFrameworkProxy = new ServiceFrameworkProxyBuilder<UserService.ServiceIface>() .setHandler(serviceHandler) .setServiceName(serviceName) .setClusterName(serviceName.toLowerCase()) .setServerSetPath(serverSetPath) .setClientNameProvider(new DefaultClientNameProvider()) .setRootLog(LOG) .setFailureLog(FAILURE_LOG) .enableExceptionTypeForFailureCount() .disableLoggingForThrowable(ClientDiscardedRequestException.class) .disableThrowablesAsServiceFailure( Arrays.asList(ClientDiscardedRequestException.class, DataValidationException.class)) .enableMethodNameForSuccessCountV2() .enableMethodNameForFailureCountV2() .enableMethodNameForResponseTimeMetricsV2() .enableClientNameTagForSuccessCount() .enableClientNameTagForFailureCount() .enableClientNameTagForResponseTimeMetrics() .enableExceptionLog() .build();
  • 27. Complaint 1: ● Clients are noticing higher latency or timeouts during deploys or restarts. First few requests take longer than at steady state due to connection establishment, Java’s Hopspot JIT etc. Solution: Use warmUp hook and then join serverset public static boolean warmUp(Callable<Boolean> warmUpCall) // By default, invokes warmUpCall 100 times concurrently and expects it succeeds for at least 80% of the calls
  • 28. Graceful Shutdown ● Unjoin from serverset, waits for duration/2 secs and then tries to gracefully shutdown server by draining existing requests within the remaining duration/2 secs ServiceShutdownHook.register(server, Duration.fromSeconds(10), status) public static void register(final Server server, final Duration gracePeriod, final ServerSet.EndpointStatus endpointStatus)
  • 29. Complaint 2: Client is seeing rate limiting Exceptions even though rate limits are set to a high value Happens if the the server cluster is huge and the local rate limit per node becomes small and the python client is running on few nodes (pinlater, offline job etc) Solution: Try reducing max_connection_lifespan_ms if its python thriftmux client
  • 30. Next steps ● Finagle upgrade to 6.43 ○ Unlocks Retry Budgets ○ Defaults to P2C Load balancer instead of heap ○ Toggle between Netty3 and Netty4 ○ Couple of performance fixes in Future scheduler ○ Many more...
  • 31. Resources: “Your server as a function” paper - https://dl.acm.org/citation.cfm?id=2525538 Source code: https://github.com/twitter/finagle Finaglers - https://groups.google.com/d/forum/finaglers Blogs: [1] https://twitter.github.io/scala_school/finagle.html [2] https://twitter.github.io/finagle/guide/developers/Futures.html [3] http://vkostyukov.net/posts/finagle-101/

Editor's Notes

  • #6: Server modules/ client modules
  • #11: history
  • #12: Internal state machine - Waiting, Interruptible, Transforming, Interrupted, Linked, and Done.
  • #13: How is a future fulfilled? Stack traces