-
Notifications
You must be signed in to change notification settings - Fork 9
Supporting multi-process (forked) applications #9
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
Comments
For inspiration, I found this relevant thread about registering hooks for when the host process is forked. A more robust solution proposed in the thread would be to simply check I tried this solution (#10) and confirmed it fixed the problem for us. |
👋 @charlypoly is there anything else I can do to help with this? |
Hi @rperryng, After a quick review, it seems that your proposed implementation might lead to some deadlock situations. |
Hi @rperryng, sorry for the delay; I was working on other matters 👀 I've conducted tests with Puma in clustered mode locally using the k6 setup present in the project and reproduced the issue (some operations were missing). require 'graphql'
require 'graphql-hive'
# tell GraphQL Hive client to send operations in buffer before shutting down in clustered mode
on_worker_shutdown { |_key| GraphQL::Hive.instance&.on_exit } Could you try this and let me know? |
@charlypoly I tried your suggestion but unfortunately still wasn't able to get data to push through. I think the problem you describe is different - operations in the buffer not being flushed when the worker is shut down. The problem I am having is that when the worker boots up (when for example, I added a log to print the queue size whenever operations are added into it, and you can see it growing past the queue limit here: these logs are over a span of about 5 minutes My understanding is that because we are using the Did you use |
Also FWIW, I tried out adding a |
@charlypoly happy new year! Any thoughts on the above? |
Uh oh!
There was an error while loading. Please reload this page.
Hey there.
We have noticed that in our staging/production environments that usage operation is not propagating to our GraphQL Hive instance (but schema publishing works)
We're using the
graphql-ruby-hive
plugin with arails
server. Locally we run the server directly withbundle exec rails server
but in our staging/production environments we use puma in its clustered (multi-process) mode.We also make use of puma's
preload_app!
directive. Therefore, in staging/production our puma preloads the Rails application (including initializating the GraphQL Hive plugin), and thenfork
s this process before serving requests using one of the worker process's thread pools.From my understanding, POSIX
fork()
does not copy threads, so once puma forks the process, a copy of the empty, just-intiializedQueue
exists in the new worker processes but the thread that was spawned to consume the messages is not copied post-fork.So with all that said, what I believe is happening is:
GraphQL::Hive::UsageReporter
gets initialized, spins up thread to continuously read from theQueue
structureQueue
but never get read out of thema. I confirmed this behaviour with a forked version of the gem with extra debugging logs
I have also confirmed that this behaviour goes away when running our web server in a non-clustered mode.
I'm unsure of the best way to support this use-case.
Puma does offer the
on_worker_boot
callback (i.e. a postfork
hook). Theoretically, ifGraphQL::Hive
offered a way to control when it spawns the Queue thread, then we could use this hook to ensure the thread is created in thefork
-ed processes.What do you think?
Happy to implement a solution if you've got any guidance/opinions etc.
The text was updated successfully, but these errors were encountered: