antonputra / tutorials

DevOps Tutorials
https://youtube.com/antonputra
MIT License
3.2k stars 2.5k forks source link

Lession 220: Ruby without Rails implementation #330

Closed simpl1g closed 3 weeks ago

simpl1g commented 3 weeks ago

I'm wondering if it is possible to test Pure Ruby. On my local M1 I see 25x improvement on get devices endpoint and 10x for create device.

simpl1g commented 3 weeks ago

@antonputra Thank you!

Just a quick question, do you use http_* metrics for prometheus? Or only myapp_request_duration_seconds for DB latency?

I will try to improve Rails performance today/tomorrow as well

antonputra commented 3 weeks ago

@simpl1g No, I don't use internal HTTP metrics because it's hard to compare them between different applications. I use an external client that exposes HTTP metrics, which is more accurate and application-agnostic.

antonputra commented 3 weeks ago

@simpl1g when i run it with 2 workers WORKERS_NUM=2 RAILS_MAX_THREADS=2 bin/iodine -p 8080 config.ru I get the following error

objc[21226]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called.
objc[21226]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

with a single worker it works just fine WORKERS_NUM=1 RAILS_MAX_THREADS=2 bin/iodine -p 8080 config.ru is this expected behavior?

Command that i use

curl -i http://localhost:8080/api/devices -d '{"mac": "81-6E-79-DA-5A-B2", "firmware": "4.0.1"}' -H "Content-Type: application/json"

Which is fine for my test comparing it with single-threaded Node.js; I'm just curious about that behavior.

simpl1g commented 3 weeks ago

If you running on mac you should add OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

WORKERS_NUM=2 OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES bin/iodine -p 8080 config.ru

RAILS_MAX_THREADS does not have any effect now, because Fibers are used now

antonputra commented 3 weeks ago

@simpl1g Thank you for clarifying this