-
Notifications
You must be signed in to change notification settings - Fork 5
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
Forking instructions unnecessary for multi-process environments? #16
Comments
Hey @hibachrach, happy to help here. The SDK uses a singleton with multiple background threads to fetch values and flush logs. If the SDK is not initialized in these specific spots, it may end up in a invalid state and not work as intended. Are you running into issues with initialization in Sidekiq that we need to fix, either with code or better documentation? |
No issues! Just confused on the guidance. When For a multithreaded environment, what you're describing makes total sense--there, memory is shared and care must be taken to avoid invalidation/corruption. But in a multi-process environment, it's not clear why this is necessary. |
after_fork is just a convenient place put the Statsig initialization as it would happen on Worker startup. This will ensure that each Worker has an initialized Statsig instance to interact with. If you have a different, centralized location you would like to put it, it should be fine. The main thing to be wary of is that you must initialize before calling any other Statsig methods, otherwise an UninitializedError will be raised. I believe the highlighted locations are valid call sites for initialize but I may be misunderstanding your meaning. |
After reading the code, it's unclear to me why the Statsig docs call for initializing the lib in a
fork
callback for Unicorn/Puma setups. Is the library using a shared system resource like a file descriptor or shared socket that isn't properly isolated via Ruby's copy-on-write?If it is necessary, it's probably worth calling out for Sidekiq when in multi-process/"swarm" mode.
The text was updated successfully, but these errors were encountered: