Skip to content

Instantly share code, notes, and snippets.

@elhoyos
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save elhoyos/ade5b69122bcdeba93fe to your computer and use it in GitHub Desktop.

Select an option

Save elhoyos/ade5b69122bcdeba93fe to your computer and use it in GitHub Desktop.
Thread-safe code in Rails

Thread-safe code in Rails

It's not hard to write thread-safe code in a Rails application. Simple rules will save any app:

Don't share mutable state If you must share mutable state, mutex around all accesses to it

rails/rails#6685 (comment)

If config.threadsafe! is enabled and code is Non-threadsafe

In multi-process environments "would have little to no impact".

In multi-threaded environment the story is completely different.

http://tenderlovemaking.com/2012/06/18/removing-config-threadsafe.html

Processes and Threads environments

Passenger and Unicorn are both multi-process.

Passenger Enterprise can be configure as multi-threaded: http://www.modrails.com/documentation/Users%20guide%20Nginx.html#PassengerConcurrencyModel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment