Lazy Rack: is there a rack middleware that will print stats like how many requests per second? Need to test some async HTTP code that sends lots of requests.
#ruby #rack #middleware
@postmodern would Rack calculate that… per thread? Or a shared process-wide calculation? Either way, you’d need to roll-up across all processes and nodes, yeah?
@postmodern I wrote up a quick gist you can use directly in your Gemfile or modify however you like
```
gem "rack-request_stats", gist: "jgaskins/8fa816a78dc15b7c210fb0503b9ab1ff"
```
```
require "bundler/setup"
require "rack-request_stats"
class App
def call(env)
[200, {"content-type" => "text/plain"}, ["hello"].freeze]
end
end
use Rack::RequestStats
run App.new
```
https://gist.github.com/jgaskins/8fa816a78dc15b7c210fb0503b9ab1ff
@postmodern It outputs like this:
```
➜ rack_stats ruby --yjit -S rackup -q
------8<-------
I, [2024-05-10T20:28:48.584115 #50773] INFO -- : #<struct Rack::RequestStats::Stats count=35, requests_per_sec=34.79222085858553, concurrent=0>
I, [2024-05-10T20:28:49.589550 #50773] INFO -- : #<struct Rack::RequestStats::Stats count=7770, requests_per_sec=7727.752377226935, concurrent=0>
````
@jamie nice and thank you!
Appears that using puma and YJIT, there's no real difference between 10 async fibers vs. 100 async fibers. Each averages at ~1k requests per second. Which at least tells me I can bruteforce ~1k directories per second.