Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from thin to puma for the web server #25

Merged
merged 3 commits into from
Dec 10, 2024
Merged

Migrate from thin to puma for the web server #25

merged 3 commits into from
Dec 10, 2024

Conversation

j05h
Copy link
Contributor

@j05h j05h commented Nov 21, 2024

What? Why?

Thin still does not support Rack 3.0, which is needed because Sinatra needs an update due to GHSA-hxx2-7vcw-mqr3.

Given the Thin update is almost a year old, this PR migrates from Thin to Puma as the server for metrics.

How was it tested?

Integrated with a Rails app:

❯ curl 0.0.0.0:9466/metrics
# HELP ruby_collector_metrics_total Total metrics processed by exporter.
# TYPE ruby_collector_metrics_total counter
ruby_collector_metrics_total 4


# HELP ruby_collector_sessions_total Total send_metric sessions processed by exporter.
# TYPE ruby_collector_sessions_total counter
ruby_collector_sessions_total 4


# HELP ruby_collector_bad_metrics_total Total mis-handled metrics by collector.
# TYPE ruby_collector_bad_metrics_total counter



# HELP ruby_collector_working Is the main process collector able to collect metrics
# TYPE ruby_collector_working gauge
ruby_collector_working 1


# HELP ruby_collector_rss total memory used by collector process
# TYPE ruby_collector_rss gauge
ruby_collector_rss 127296

# HELP ruby_heap_free_slots Free ruby heap slots.
# TYPE ruby_heap_free_slots gauge
ruby_heap_free_slots{type="web",pid="12741"} 48754

# HELP ruby_heap_live_slots Used ruby heap slots.
# TYPE ruby_heap_live_slots gauge
ruby_heap_live_slots{type="web",pid="12741"} 477767

# HELP ruby_rss Total RSS used by process.
# TYPE ruby_rss gauge
ruby_rss{type="web",pid="12741"} 0

# HELP ruby_major_gc_ops_total Major GC operations by process.
# TYPE ruby_major_gc_ops_total counter
ruby_major_gc_ops_total{type="web",pid="12741"} 9

# HELP ruby_minor_gc_ops_total Minor GC operations by process.
# TYPE ruby_minor_gc_ops_total counter
ruby_minor_gc_ops_total{type="web",pid="12741"} 56

# HELP ruby_allocated_objects_total Total number of allocated objects by process.
# TYPE ruby_allocated_objects_total counter
ruby_allocated_objects_total{type="web",pid="12741"} 3003928

# HELP ruby_puma_workers_total Number of puma workers.
# TYPE ruby_puma_workers_total gauge
ruby_puma_workers_total{phase="0"} 3

# HELP ruby_puma_booted_workers_total Number of puma workers booted.
# TYPE ruby_puma_booted_workers_total gauge
ruby_puma_booted_workers_total{phase="0"} 0

# HELP ruby_puma_old_workers_total Number of old puma workers.
# TYPE ruby_puma_old_workers_total gauge
ruby_puma_old_workers_total{phase="0"} 0

Resident set size (RSS) graph for a simple Rails app. 14:45-16:00 is the period we had this deployed (along with an upgrade from Rails 7.0 to 7.1). The memory footprint does grow, but only by about 3mb.

Screenshot 2024-12-10 at 8 26 44 AM

@j05h j05h self-assigned this Nov 21, 2024
@j05h j05h requested a review from a team as a code owner November 21, 2024 14:46
@j05h j05h changed the title PoC migrating from thign to puma PoC migrating from thin to puma Nov 21, 2024
@j05h j05h changed the title PoC migrating from thin to puma Migrate from thin to puma for the web server Dec 5, 2024
Copy link
Member

@splittingred splittingred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Any impact to memory usage relative to thin?

@splittingred
Copy link
Member

Also @j05h - does this cause any issue when being used alongside another Puma server in a separate thread?

@j05h
Copy link
Contributor Author

j05h commented Dec 9, 2024

Also @j05h - does this cause any issue when being used alongside another Puma server in a separate thread?

I haven't seen any issues to date. We've upgraded an app with Rails 7.1 and are doing some testing on that now.

@j05h
Copy link
Contributor Author

j05h commented Dec 9, 2024

Looks good. Any impact to memory usage relative to thin?

They seem relatively equivalent.

On thin:

❯ top -l 1 | grep 68335 | awk '{print "MEM="$8 "\tCMPRS="$10}'
MEM=62M	CMPRS=59M
MEM=62M	CMPRS=59M
MEM=62M	CMPRS=59M
MEM=2401K	CMPRS=2032K
MEM=2657K	CMPRS=2288K
MEM=168M	CMPRS=110M

On Puma:

❯ top -l 1 | grep "60714" | awk '{print "MEM="$8 "\tCMPRS="$10}'
MEM=55M	CMPRS=53M
MEM=52M	CMPRS=49M
MEM=52M	CMPRS=50M
MEM=2305K	CMPRS=1920K
MEM=2769K	CMPRS=2384K
MEM=165M	CMPRS=158M

This is local on my Mac, so likely its not an Apples-to-Penguins comparison to Linux. Will try to get some data from our test app.

@j05h j05h merged commit ae9b65c into main Dec 10, 2024
13 checks passed
@j05h j05h deleted the puma-webserver branch December 10, 2024 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants