You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When spring is already loaded, Spring takes 1.5 seconds to boot:
$ time (rails c)
Loading development environment (Rails 5.1.6)
[1] pry(main)>
( rails c; ) 0.24s user 0.10s system 22% cpu 1.521 total
1.5 seconds is too long, booting rails should feel instant since spring is already loaded.
Notes
Removing the LD config from Spring makes Rails boot back to 0.5 seconds, which is ideal. But then the LD client will fail to receive updates.
Is there any way to make the LD client work with Spring while not impacting Spring boot time? Because at the moment this makes all our Spring commands (console, rspec, rake tasks...) slower by a good 1 second.
If I understand correctly, it sounds like what you want is a client that doesn't actually get initialized until you need to use it. This is somewhat problematic because initialization of the client is not thread-safe, and if you wait until some later point in the application to create the client on demand, you could end up with several threads each trying to call LdClient.new.
Unfortunately, we haven't used Spring with Ruby, so I'm not sure what other options there may be to control the boot process. I can only hope that there is some way to detect if your application is really being started, or if it is just initializing Spring because you're running some other Spring command, and only call LdClient.new in the former case.
Then we make our code call LdClient.client whenever LaunchDarkly needs to be called. This means that Spring is not slowed down at startup, and the client will be lazily initialized for each of our web server processes. This may not be thread-safe, but we use the Unicorn web server which uses forked processes, not threads. So this works for us for now.
Activity
[-]Spring is slow[/-][+]Spring is slow with LD enabled[/+][-]Spring is slow with LD enabled[/-][+]Spring is slow with LaunchDarkly enabled[/+]eli-darkly commentedon Jul 27, 2018
If I understand correctly, it sounds like what you want is a client that doesn't actually get initialized until you need to use it. This is somewhat problematic because initialization of the client is not thread-safe, and if you wait until some later point in the application to create the client on demand, you could end up with several threads each trying to call
LdClient.new.Unfortunately, we haven't used Spring with Ruby, so I'm not sure what other options there may be to control the boot process. I can only hope that there is some way to detect if your application is really being started, or if it is just initializing Spring because you're running some other Spring command, and only call
LdClient.newin the former case.jeromedalbert commentedon Aug 8, 2018
We ended up doing just that. This is approximately what we did:
Then we make our code call
LdClient.clientwhenever LaunchDarkly needs to be called. This means that Spring is not slowed down at startup, and the client will be lazily initialized for each of our web server processes. This may not be thread-safe, but we use the Unicorn web server which uses forked processes, not threads. So this works for us for now.Merge pull request #105 from launchdarkly/eb/ch32304/experiment