A truly parallel server for CRuby
MIT License
Mooro is a Ractor-based, compact, parallel TCP server targeting CRuby. It is built to be extended - you can only do so much with raw TCP sockets - and offers straigtforward ways (and examples) of doing so.
Mooro aims to deliver all essential features expected from a modern Ruby web server such as
Ractor
s.logger.send("message")
.At the same time, it abstracts virtually nothing away from TCPServer, enabling maximum extensibility. Anything at the TCP level and higher is fair game for Mooro. Extending Mooro is quite simple because it is
If you want to create a basic server that outputs the time,
class TimeServer < Mooro::Server
def serve(io)
io.puts(Time.now.to_i)
end
end
server = TimeServer.new(max_connections = 4)
server.start
sleep(15)
server.stop
Mooro ships with an implementation of an HTTP Server. A healthcheck server can be built with
HTTP = Mooro::Plugin::HTTP
class HealthCheck < Mooro::Server
include HTTP
def handle_request(req)
req.path == "/" ? HTTP::Response[200] : HTTP::Response[404]
end
end
Install the gem and add to the application's Gemfile by executing:
$ bundle add mooro
If bundler is not being used to manage dependencies, install the gem by executing:
$ gem install mooro
After checking out the repo, run bin/setup
to install dependencies. Then, run rake spec
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and the created tag, and push the .gem
file to rubygems.org.
Mooro is in desperate need of Tests (both Unit and Integration) and Benchmarks. I unfortunately lack the expertise needed for thoroughly handling these, so any contribution in these areas are greatly appreciated. Furthermore, another, more practicality focused priority is the rack-ification of Mooro. Rack is undoubtedly the gold standard interface for HTTP applications. Mooro is technically fully capable of supporting Rack, but the big hurdle currently is properly parsing HTTP requests (yuck).
Contributions outside these areas are, of course, also welcome.
Bug reports and pull requests are welcome on GitHub at https://github.com/Forthoney/mooro. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
Ractor
s are still experimental as of 3.2.2
. Subsequently, Mooro should be treated as experimental.
Mooro is quite incompatible with older versions of Ruby. Anything pre-Ractor
(i.e. pre 3.0) obviously does not work.
The builtin HTTP Server requires Ruby 3.2 or later, although this can easily be circumvented if need be.
Mooro's interface is not exactly like gserver
. Read more about the differences here.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the Mooro project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.