Polyphony is a library for building concurrent applications in Ruby. Polyphony implements a comprehensive fiber-based concurrency model, using libev as a high-performance event reactor for I/O, timers, and other asynchronous events.
Polyphony is designed to make concurrent Ruby programming feel natural and fluent. The Polyphony API is easy to use, easy to understand, and above all idiomatic.
Polyphony offers high performance for I/O bound Ruby apps. Distributing concurrent operations over fibers, instead of threads or processes, minimizes memory consumption and reduces the cost of context-switching.
With Polyphony you can use any of the stock Ruby classes and modules like
OpenSSL in a concurrent multi-fiber environment. In addition, Polyphony provides a structured model for exception handling that builds on and enhances Ruby’s exception handling system.
Polyphony includes a full-blown HTTP server implementation with integrated support for HTTP 2, WebSockets, TLS/SSL termination and more. Polyphony also provides fiber-aware adapters for connecting to PostgreSQL and Redis. More adapters are being developed.
- 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: supervisors, throttling, resource pools etc.
- Code can use native networking classes and libraries, growing support for third-party gems such as
- Use stdlib classes such as
- 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 started as a spinoff of nio4r’s)
- The go scheduler
- Erlang supervisors (and actually, Erlang in general)
Issues and pull requests will be gladly accepted. Please use the Polyphony git repository as your primary point of departure for contributing.