DEV Community

Ciro Spaciari
Ciro Spaciari

Posted on

3 3

Faster and simple Http and WebSocket Server for Ruby

uWebSockets for Ruby - uWebSockets.rb

I started to implement uWebSockets C API wrapper and a Ruby version a few days ago.
I got some good performance results (about 5x agoo in using techempower benchmarks for plaintext), for now i just implemented http/https apis but i will implement websockets this week and write some documentation (only linux support, mac should works fine as well, but i will add windows and mac tests and support too)

I will be glad for some feedback and help for testing in the near future https://github.com/cirospaciari/uWebSockets.rb

Overly simple hello world app

require "uws"

UWS::App.new()
.get("/", lambda {|response, request| response.end("Hello World uWS from Ruby!")})
.listen(8082, lambda {|config| puts "Listening on port #{config.port}" })
.run()
Enter fullscreen mode Exit fullscreen mode

Gemfile

gem 'uws', git: 'https://github.com/cirospaciari/uWebSockets.rb.git', branch: 'main', submodules: true
Enter fullscreen mode Exit fullscreen mode

Run

bundle exec ruby ./hello_world.rb
Enter fullscreen mode Exit fullscreen mode

SSL version sample

require "uws"

UWS::SSLApp.new({
    key_file_name: "./misc/key.pem",
    cert_file_name: "./misc/cert.pem", 
    passphrase: "1234"
})
.get("/", lambda {|response, request| response.end("Hello World uWS from Ruby!")})
.listen(8082, lambda {|config| puts "Listening on port #{config.port}" })
.run()
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

The best way to debug slow web pages cover image

The best way to debug slow web pages

Tools like Page Speed Insights and Google Lighthouse are great for providing advice for front end performance issues. But what these tools can’t do, is evaluate performance across your entire stack of distributed services and applications.

Watch video

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay