`
wooce
  • 浏览: 184734 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

[ZT]Finagle: A Protocol-Agnostic RPC System

    博客分类:
  • Java
 
阅读更多

Source from: Finagle: A Protocol-Agnostic RPC System

 Finagle is a protocol-agnostic, asynchronous RPC system for the JVM that makes it easy to build robust clients and servers in Java, Scala, or any JVM-hosted language.

Rendering even the simplest web page on twitter.com requires the collaboration of dozens of network services speaking many different protocols. For example, in order to render the home page, the application issues requests to the Social Graph Service, Memcached, databases, and many other network services. Each of these speaks a different protocol: Thrift, Memcached, MySQL, and so on. Additionally, many of these services speak to other services — they are both servers and clients. The Social Graph Service, for instance, provides a Thrift interface but consumes from a cluster of MySQL databases.

In such systems, a frequent cause of outages is poor interaction between components in the presence of failures; common failures include crashed hosts and extreme latency variance. These failures can cascade through the system by causing work queues to back up, TCP connections to churn, or memory and file descriptors to become exhausted. In the worst case, the user sees a Fail Whale.

CHALLENGES OF BUILDING A STABLE DISTRIBUTED SYSTEM

Sophisticated network servers and clients have many moving parts: failure detectors, load-balancers, failover strategies, and so on. These parts need to work together in a delicate balance to be resilient to the varieties of failure that occur in a large production system.

This is made especially difficult by the many different implementations of failure detectors, load-balancers, and so on, per protocol. For example, the implementation of the back-pressure strategies for Thrift differ from those for HTTP. Ensuring that heterogeneous systems converge to a stable state during an incident is extremely challenging.

OUR APPROACH

We set out to develop a single implementation of the basic components of network servers and clients that could be used for all of our protocolsFinagle is a protocol-agnostic, asynchronous Remote Procedure Call (RPC) system for the Java Virtual Machine (JVM) that makes it easy to build robust clients and servers in Java, Scala, or any JVM-hosted language. Finagle supports a wide variety of request/response- oriented RPC protocols and many classes of streaming protocols.

Finagle provides a robust implementation of:

  • connection pools, with throttling to avoid TCP connection churn;
  • failure detectors, to identify slow or crashed hosts;
  • failover strategies, to direct traffic away from unhealthy hosts;
  • load-balancers, including “least-connections” and other strategies; and
  • back-pressure techniques, to defend servers against abusive clients and dogpiling.

Additionally, Finagle makes it easier to build and deploy a service that

  • publishes standard statistics, logs, and exception reports;
  • supports distributed tracing (a la Dapper) across protocols;
  • optionally uses ZooKeeper for cluster management; and
  • supports common sharding strategies.

We believe our work has paid off — we can now write and deploy a network service with much greater ease and safety.

FINAGLE AT TWITTER

Today, Finagle is deployed in production at Twitter in several front- and back-end serving systems, including our URL crawler and HTTP Proxy. We plan to continue deploying Finagle more widely.

Finagle-Diagram

A Finagle-based architecture (under development)The diagram illustrates a future architecture that uses Finagle pervasively. For example, the User Service is a Finagle server that uses a Finagle memcached client, and speaks to a Finagle Kestrel service.

 

HOW FINAGLE WORKS

Finagle is flexible and easy to use because it is designed around a few simple, composable primitives: FuturesServices, and Filters.

Future objects

In Finagle, Future objects are the unifying abstraction for all asynchronous computation. A Future represents a computation that may not yet have completed and that can either succeed or fail. The two most basic ways to use a Future are to:

  • block and wait for the computation to return
  • register a callback to be invoked when the computation eventually succeeds or fails <h3Future callbacksIn cases where execution should continue asynchronously upon completion of a computation, you can specify a success and a failure callback. Callbacks are registered via the onSuccess and onFailure methods:

Composing Futures

Futures can be combined and transformed in interesting ways, leading to the kind of compositional behavior commonly seen in functional programming languages. For instance, you can convert a Future[String] to a Future[Int] by using map:

Similarly, you can use flatMap to easily pipeline a sequence of Futures:

In this example, User.authenticate() is performed asynchronously;Tweet.findAllByUser() is invoked on its eventual result. This is alternatively expressed in Scala, using the for statement:

Handling errors and exceptions is very easy when Futures are pipelined using flatMapor the for statement. In the above example, if User.authenticate()asynchronously raises an exception, the subsequent call to Tweet.findAllByUser()never happens. Instead, the result of the pipelined expression is still of the typeFuture[Seq[Tweet]], but it contains the exceptional value rather than tweets. You can respond to the exception using the onFailure callback or other compositional techniques.

A nice property of Futures, as compared to other asynchronous programming techniques (such as the continuation passing style), is that you an easily write clear and robust asynchronous code, even with more sophisticated operations such as scatter/gather:

Service objects

Service is a function that receives a request and returns a Future object as a response. Note that both clients and servers are represented as Service objects.

To create a Server, you extend the abstract Service class and listen on a port. Here is a simple HTTP server listening on port 10000:

Building an HTTP client is even easier:

Filter objects

Filters are a useful way to isolate distinct phases of your application into a pipeline. For example, you may need to handle exceptions, authorization, and so forth before your Service responds to a request.

Filter wraps a Service and, potentially, converts the input and output types of the Service to other types. In other words, a Filter is a Service transformer. Here is a filter that ensures an HTTP request has valid OAuth credentials that uses an asynchronous authenticator service:

Filter then decorates a Service, as in this example:

Finagle is an open source project, available under the Apache License, Version 2.0. Source code and documentation are available on GitHub.

ACKNOWLEDGEMENTS

Finagle was originally conceived by Marius Eriksen and Nick Kallen. Other key contributors are Arya Asemanfar, David Helder, Evan Meagher, Gary McCue, Glen Sanford, Grant Monroe, Ian Ownbey, Jake Donham, James Waldrop, Jeremy Cloud, Johan Oskarsson, Justin Zhu, Raghavendra Prabhu, Robey Pointer, Ryan King, Sam Whitlock, Steve Jenson, Wanli Yang, Wilhelm Bierbaum, William Morgan, Abhi Khune, and Srini Rajagopal.

  • 大小: 26.3 KB
  • 大小: 39.1 KB
分享到:
评论

相关推荐

    Finagle:容错、协议无关的 RPC 系统-开源

    Finagle 是 JVM 的可扩展 RPC 系统,用于构建高并发服务器。 Finagle 为多种协议实现了统一的客户端和服务器 API,并且专为高性能和并发而设计。 Finagle 的大部分代码与协议无关,简化了新协议的实现。 Finagle 是...

    finagle-example_2.9.2-6.2.0.zip

    【标题】"finagle-example_2.9.2-6.2.0.zip" 提供的是Finagle框架的一个示例项目,版本号为2.9.2-6.2.0。Finagle是Twitter开发的一个分布式服务框架,它允许开发者用Scala、Java或Finagle原生的Thrift语言来构建高...

    finagle:容错,与协议无关的RPC系统

    Finagle是JVM的可扩展RPC系统,用于构建高并发服务器。 Finagle为几种协议实现了统一的客户端和服务器API,并且旨在实现高性能和并发性。 Finagle的大多数代码都是协议无关的,从而简化了新协议的实现。 有关详尽...

    finagle-clojure:围绕Finagle的薄Clojure包装纸

    梭子豆 围绕Finagle和Twitter Future的薄包装。 该库假定您熟悉Finagle。... finagle-clojure-template :用于使用finagle-clojure和Thrift创建新项目的lein模板。用Thrift创建一个新项目lein new fin

    finagle-mux_2.9.2-6.12.1.zip

    《Finagle-Mux与Pact-JVM:构建高效微服务契约测试》 在现代软件开发中,微服务架构已经成为主流,各个服务之间的交互变得尤为重要。为了确保这些服务间通信的可靠性,开发者需要进行契约测试。本文将深入探讨两个...

    http4s-finagle:Finagle服务器或客户端上的Http4s

    它提供了一种优雅的方式来构建RESTful API和服务,而Finagle则是Twitter开源的一个高可扩展、高性能的服务框架,用于构建分布式系统。当Http4s与Finagle结合时,它们可以创建出强大且高效的Scala Web服务器和客户端...

    finagle-http-thrift-example:Finagle HTTP 和 Thrift Clients \ Servers 示例

    Finagle HTTP 和 Thrift Clients \ Servers 示例这是如何编写 Finagle HTTP/Thrift 服务器/客户端的示例。尝试一下! 要尝试它,您应该通过以下命令运行 HTTP: $ sbt "run-main com.acme.Example.HttpServer"然后你...

    finagle-http-server-example:Finagle 项目示例

    Finagle 是一个由 Twitter 开发并开源的高性能、可扩展且模块化的 RPC 系统,主要面向 Scala 和 Java 语言。这个"finagle-http-server-example"项目是专门为展示如何使用 Finagle 构建 HTTP 服务器而设计的。下面将...

    finagle-serverset-example

    Finagle ServerSet 示例 这是一个快速示例,说明如何将 finagles “新”服务器设置与 zookeeper 解析器一起使用。 通过 new 我指的是在不引用ClientBuilder或ServerBuilder api 的情况下进行设置。 这个项目是用 sbt...

    finagle-redis-sample:这是一个使用 Redis 的 Finagle 客户端 hello world

    使用 Finagle Redis 客户端的示例应用程序要运行示例,请在默认端口 (6379) 上本地启动 Redis,然后执行: cd finagle-redis-samplesbt run享受 !! (是) :)

    finagle-java-example-master-slave:Finagle 示例与主从设计中的服务,管理长时间运行的任务

    在这个"finagle-java-example-master-slave"项目中,我们将探讨如何使用Finagle在Java环境中实现主从架构,以管理和执行长时间运行的任务。 主从架构是一种常见的分布式系统设计模式,其中有一个或多个主节点...

    finagle-serversets_2.10-6.16.0.zip

    【标题】"finagle-serversets_2.10-6.16.0.zip" 涉及的是一款基于Scala构建的Finagle框架的扩展,用于与Zookeeper的Serversets进行交互。Finagle是Twitter开源的一个分布式服务框架,它提供了一种声明式的RPC系统,...

    finagle-test_2.9.2-6.15.0.zip

    【标题】"finagle-test_2.9.2-6.15.0.zip" 提供的是Twitter的Finagle测试框架的一个版本,该框架是基于Scala的,用于构建高效的、可扩展的网络服务。Finagle是Twitter开源的一个分布式服务框架,它支持多种协议,如...

    finagle-redis-master-slave-sample:带有手动负载平衡的 Finagle 的简单自定义 Redis 客户端

    finagle-redis-master-slave-sample 用于 Finagle 的简单自定义 Redis 客户端,具有手动负载平衡。 为了运行示例,需要在 :6379 上使用本地 Redis,并且代码应该能够查询正确的服务器。 当然,完整的 Redis 主/从...

    finagle-thriftmux_2.9.2-6.4.1.zip

    【标题】"finagle-thriftmux_2.9.2-6.4.1.zip" 涉及的是一款基于Scala构建的Finagle库,它提供了ThriftMux协议的实现。Finagle是Twitter开源的一个高可扩展、高性能的服务框架,用于构建分布式系统。ThriftMux是...

    finagle-kafka, 在联网和Finagle中,Apache Kafka 客户端.zip

    finagle-kafka, 在联网和Finagle中,Apache Kafka 客户端 finagle-kafka联网和Finagle中的Apache Kafka 客户端。概述是 Finagle Kafka 是在网联网客户端和 Twitter的 Finagle 。 它使你能够以更功能的方式处理 Kafka...

    finagle-example-name-finder:Finagle的例子

    Finagle名称查找器 该项目演示了如何使用Finagle构建服务,该服务将在您输入的任何文本中标识人员,地点和组织的名称。 它主要用作教学示例,并在教授的“ Finagle Essentials”课程中使用(您可以在查看该课程的...

    go-rpc-programming-guide.pdf

    RPC(Remote Procedure Call,远程过程调用)是一种计算机通信协议,它允许计算机程序调用另一台计算机上的子程序,而开发者无需为这个远程交互过程编写特定的网络通信代码。RPC的基本工作模式是客户端-服务器模型,...

    finagle, 一种容错协议无关RPC系统.zip

    finagle, 一种容错协议无关RPC系统 Finagle 状态项目已经在 Twitter ( 还有很多其他组织)的生产中使用,正在积极开发和维护。 插件发布在大约每月的时间内完成了发布。 在不遵循时,将详细说明 changelogs插件,并...

    finagle-metrics:将Finagle指标发送到Codahale Metrics库的简便方法

    《Finagle-Metrics:连接Finagle与Codahale Metrics的桥梁》 Finagle-Metrics是Scala社区中的一个实用工具,它提供了一种简洁有效的方法,将Finagle服务的监控指标发送到Codahale Metrics库。这个库使得Finagle,一...

Global site tag (gtag.js) - Google Analytics