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.
- Programming a Ruby gem for concurrent programming focusing on performance and developer happiness.
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.
- 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, throttling, resource pools etc.
- Code can use native networking classes and libraries, growing support for
third-party gems such as
pg
andredis
. - Use stdlib classes such as
TCPServer
andTCPSocket
andNet::HTTP
. - HTTP 1 / HTTP 2 client agent with persistent connections.
- Competitive performance and scalability characteristics, in terms of both throughput and memory consumption.
Polyphony draws inspiration from the following, in no particular order:
- nio4r and async (Polyphony's C-extension code is largely a spinoff of nio4r's)
- EventMachine
- Trio
- Erlang supervisors (and actually, Erlang in general)
To learn more about using Polyphony to build concurrent applications, read the technical overview below, or look at the included examples. A thorough reference is forthcoming.
Issues and pull requests will be gladly accepted. Please use the git repository at https://github.com/digital-fabric/polyphony as your primary point of departure for contributing.