Polyphony - Easy Concurrency for Ruby

Gem Version Modulation Test MIT licensed

DOCS | EXAMPLES

Polyphony | pəˈlɪf(ə)ni | Music - the style of simultaneously combining a number of parts, each forming an individual melody and harmonizing with each other.

What is Polyphony

Polyphony is a library for building concurrent applications in Ruby. Polyphony harnesses the power of Ruby fibers to provide a cooperative, sequential coprocess-based concurrency model. Under the hood, Polyphony uses libev as a high-performance event reactor that provides timers, I/O watchers and other asynchronous event primitives.

Polyphony makes it possible to use normal Ruby built-in classes like IO, and Socket in a concurrent fashion without having to resort to threads. Polyphony takes care of context-switching automatically whenever a blocking call like Socket#accept or IO#read is issued.

Features

  • Full-blown, integrated, high-performance HTTP 1 / HTTP 2 / WebSocket server with TLS/SSL termination, automatic ALPN protocol selection, and body streaming.
  • Co-operative scheduling of concurrent tasks using Ruby fibers.
  • High-performance event reactor for handling I/O events and timers.
  • Natural, sequential programming style that makes it easy to reason about concurrent code.
  • Abstractions and constructs for controlling the execution of concurrent code: coprocesses, supervisors, cancel scopes, throttling, resource pools etc.
  • Code can use native networking classes and libraries, growing support for third-party gems such as pg and redis.
  • Use stdlib classes such as TCPServer, TCPSocket and
  • HTTP 1 / HTTP 2 client agent with persistent connections.
  • Competitive performance and scalability characteristics, in terms of both throughput and memory consumption.

Prior Art

Polyphony draws inspiration from the following, in no particular order:

Documentation

The complete documentation for Polyphony could be found on the Polyphony website.