-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref: #110 It's not uncommon for applications to want to have some background threads doing regular work for various purposes (e.g. emitting metrics, prewarming node local caches, etc). Currently the best way to do it, is to spawn some background threads in the `after_mold_fork`, but this isn't great as the mold may fork at any moment to spawn a new worker, and forking while background threads may be doing work is risky. Instead we can provide a dedicated service worker process to run these threads.
- Loading branch information
Showing
9 changed files
with
380 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# frozen_string_literal: true | ||
# Minimal sample configuration file for Pitchfork | ||
|
||
# listen 2007 # by default Pitchfork listens on port 8080 | ||
worker_processes 4 # this should be >= nr_cpus | ||
refork_after [50, 100, 1000] | ||
|
||
service_thread = nil | ||
service_shutdown = false | ||
|
||
before_service_worker_ready do |server, service| | ||
service_thread = Thread.new do | ||
server.logger.info "Service: start" | ||
count = 1 | ||
until service_shutdown | ||
server.logger.info "Service: ping count=#{count}" | ||
count += 1 | ||
sleep 1 | ||
end | ||
end | ||
end | ||
|
||
before_service_worker_exit do |server, service| | ||
server.logger.info "Service: shutting down" | ||
service_shutdown = true | ||
service_thread&.join(2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.