Finding ideal number of threads per process using GVL instrumentation

16-May-2025 15
In part 1 we saw how to find ideal number of processes for our Rails application. In part 2, we learned about Amdahl's law which helps us find the ideal number of threads theoretically. In this blog, we'll run a bunch of tests on our real production application to see what the actual number of threads should be for each process. In part 1 we discussed the presence of GVL and the concept of thread switching. Based on the GVL's interaction, a thread can be in one of these three states. Running: The thread has the GVL and is executing Ruby code. Idle: The thread doesn't want the GVL because it is performing I/O operations. Stalled: The thread wants the GVL and is waiting for it in the GVL wait queue.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle