Challenge - 5 Problems
Puma Configuration Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
Understanding Puma's thread pool behavior
Given this Puma configuration snippet, what is the maximum number of threads Puma will use concurrently?
Ruby on Rails
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i threads threads_count, threads_count
Attempts:
2 left
💡 Hint
Look at the minimum and maximum thread counts set by the threads method.
✗ Incorrect
The threads method sets both minimum and maximum threads to the same value, so Puma will use exactly 5 threads concurrently.
📝 Syntax
intermediate2:00remaining
Correct syntax for binding Puma to a TCP port
Which option correctly binds Puma to listen on TCP port 3000 on all interfaces?
Attempts:
2 left
💡 Hint
The bind method expects a string with the protocol prefix.
✗ Incorrect
The correct syntax requires the protocol prefix 'tcp://' inside quotes. Option A is correct.
🔧 Debug
advanced2:00remaining
Identify the error in Puma worker configuration
What error will this Puma configuration cause when starting the server?
workers ENV.fetch("WEB_CONCURRENCY") { 2 }
preload_app!
on_worker_boot do
ActiveRecord::Base.establish_connection
end
Ruby on Rails
workers ENV.fetch("WEB_CONCURRENCY") { 2 } preload_app! on_worker_boot do ActiveRecord::Base.establish_connection end
Attempts:
2 left
💡 Hint
This is a standard Puma configuration for Rails applications using multiple workers.
✗ Incorrect
No error; this is the recommended configuration for Puma with preload_app! and multiple workers in Rails. The establish_connection call works without parentheses as it uses the default specification.
❓ state_output
advanced2:00remaining
Effect of preload_app! on application state
What is the main effect of calling preload_app! in Puma configuration?
Attempts:
2 left
💡 Hint
Think about how forking affects memory and startup speed.
✗ Incorrect
preload_app! loads the app before forking workers, so memory pages can be shared, improving performance and reducing startup time.
🧠 Conceptual
expert2:00remaining
Choosing Puma worker count for CPU cores
If a server has 8 CPU cores and you want to optimize Puma for concurrency and memory, which worker count is best practice?
Attempts:
2 left
💡 Hint
Consider how Puma uses workers and threads relative to CPU cores.
✗ Incorrect
Best practice is to set workers equal to CPU cores to maximize CPU usage without excessive context switching. Threads handle concurrency within each worker.