Using Reuse Port for Multiple Kemal Processes
require "kemal"
get "/" do
"Reusing port 3000"
end
Kemal.run do |config|
server = config.server.not_nil!
server.bind_tcp "0.0.0.0", 3000, reuse_port: true
end
You can use the following script to spawn multiple Kemal processes according to your CPU cores.
#!/bin/bash
for i in $(seq 1 $(nproc --all)); do
./app
done
wait
Important: This is for demonstration purpose only. You should use a mature process manager / monitor for production.