Posts Tagged ‘RPC’
[ScalaDaysNewYork2016] Finagle Under the Hood: Unraveling Twitter’s RPC System
At Scala Days New York 2016, Vladimir Kostyukov, a member of Twitter’s Finagle team, provided an in-depth exploration of Finagle, a scalable and extensible RPC system written in Scala. Vladimir elucidated how Finagle simplifies the complexities of distributed systems, offering a functional programming model that enhances developer productivity while managing intricate backend operations like load balancing and circuit breaking.
The Essence of Finagle
Vladimir Kostyukov introduced Finagle as a robust RPC system used extensively at Twitter and other organizations. Unlike traditional application frameworks, Finagle focuses on facilitating communication between services, abstracting complexities such as connection pooling and load balancing. Vladimir highlighted its protocol-agnostic nature, supporting protocols like HTTP/2 and Twitter’s custom Mux, which enables efficient multiplexing. This flexibility allows developers to build services in Scala or Java, seamlessly integrating Finagle into diverse tech stacks.
Client-Server Dynamics
Delving into Finagle’s internals, Vladimir described its client-server model, where services are treated as composable functions. When a client sends a request, Finagle’s stack—comprising modules for connection pooling, load balancing, and failure handling—processes it efficiently. On the server side, incoming requests are routed through similar modules, ensuring resilience and scalability. Vladimir emphasized the “power of two choices” load balancing algorithm, which selects the least-loaded node from two randomly chosen servers, achieving near-optimal load distribution in constant time.
Advanced Features and Ecosystem
Vladimir showcased Finagle’s advanced capabilities, such as streaming support for large payloads and integration with tools like Zipkin for tracing and Twitter Server for monitoring. Libraries like Finatra and Featherbed further enhance Finagle’s utility, enabling developers to build RESTful APIs and type-safe HTTP clients. These features make Finagle a powerful choice for handling high-throughput systems, as demonstrated by its widespread adoption at Twitter for managing massive data flows.
Community and Future Prospects
Encouraging community engagement, Vladimir invited developers to contribute to Finagle’s open-source repository on GitHub. He discussed ongoing efforts to support HTTP/2 and improve performance, underscoring Finagle’s evolution toward a utopian RPC system. By offering a welcoming environment for pull requests and feedback, Vladimir emphasized the collaborative spirit driving Finagle’s development, ensuring it remains a cornerstone of scalable service architectures.
Links:
No source code is available for type … ; did you forget to inherit a required module?
Context
In a GWT application, you have to use RPC calls, using entities which are package in external jar archives. With Eclipse, no error appears ; yet when you build the project with Maven2, you get this message:
[java][INFO] [ERROR] Errors in ‘file:/C:/eclipse/workspace/myGwtProject/src/java/com/lalou/jonathan/web/gwt/client/component/JonathanPanel.java’
(…)
[INFO] [ERROR] Line 24: No source code is available for type com.lalou.jonathan.domain.MyEntity; did you forget to inherit a required module?
(…)
[INFO] Finding entry point classes[/java]
Fix
In related jar
In the project to which MyEntity belongs to (here: my/depended/project):
- create a file
com/lalou/jonathan/MyDependedProject.gwt.xml, with as content:[xml]<module>
<source path="">
<include name="**/MyEntity.java"/>
</source>
</module>[/xml] - In the pom.xml:
- Add the source
MyEntity.javain built jar. This way, the Java file itself will be considered as a resource, like an XML or property file. To perform this, the quickest manner is to add the following block in thepom.xml:
[xml]<resources>
<resource>
<directory>${basedir}/src/java</directory>
<includes>
<include>**/MyEntity.java</include>
</includes>
</resource>
</resources>[/xml] - Add an
<include>**/*.gwt.xml</include>so that to have toMyDependedProject.gwt.xmlfile in the built jar.
In GWT project
In your
*.gwt.xmlfile, add the dependency:[xml]<inherits name=’com.lalou.jonathan.MyDependedProject’ />[/xml]
Caution!
All these operations need be done on all dependencies -either direct or indirect-. Therefore, possibly you may have a huge amount of code to be got.
Another issue appears when you use a jar of which you do not have the source code, such as in the case of tiers API for instance. - Add the source
Basic RPC call with GWT
Let’s assume you have a “Hello World” GWT application. You need emulate a basic RPC call (RMI, EJB, etc.). Here is the program:
Under the *.gwt.client folder:
Create an service interface:
[java]@RemoteServiceRelativePath("fooService")
public interface FooService extends RemoteService {
public String getHelloFoo(String totoName);
}[/java]
Create another interface for asynchronous call. You can notice the method name differs lightly from the one in the other interface:
[java]public interface FooServiceAsync {
void getHelloFoo(String fooName, AsyncCallback<String> callback);
}[/java]
Under the *.gwt.server folder, create an implementation for service interface:
[java]public class FooServiceImpl extends RemoteServiceServlet implements FooService {
public FooServiceImpl() {
// TODO init
}
public String getHelloFoo(String fooName) {
// TODO call actual service
return "hello world!";
}
}[/java]
In the web.xml file, add the following blocks:
[xml] <!– Servlets –>
<servlet>
<servlet-name>fooService</servlet-name>
<servlet-class>com…….server.FooServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fooService</servlet-name>
<url-pattern>/ivargwt/fooService</url-pattern>
</servlet-mapping>
[/xml]
The tags content match the argument given as parameter to RemoteServiceRelativePath annotation above.
From then, in your concrete code, you can instantiate the service and call remote method:
[java]FooServiceAsync fooService = GWT.create(FooService.class);
fooService.getHelloFoo("how are you?", new AsyncCallback<String>() {
public void onSuccess(String result) {
MessageBox.alert("OK", result, null);
}
public void onFailure(Throwable caught) {
MessageBox.alert("ERROR", "rpc call error-" + caught.getLocalizedMessage(), null);
}
});
[/java]
Now you can compile, package your war and deploy under Tomcat or WebLogic.
NB: special to “black-belt GWT guy” David Chau from SFEIR.