config.threadsafe!: JUST DO IT

4131d2f57a0db2a2b4d9a62bd389fd44?s=47 tarcieri
April 25, 2012
1.4k

config.threadsafe!: JUST DO IT

Most Rails applications today are not running in thread-safe mode, which means that they can only one process one request at a time. This is BAD! This lightning talk covers the basics of Rails thread-safe mode and why you should use it

4131d2f57a0db2a2b4d9a62bd389fd44?s=128

tarcieri

April 25, 2012
Tweet

Transcript

  1. config.threadsafe! JUST DO IT Tony Arcieri RailsConf 2012 Wednesday, April

    25, 12
  2. Most Rails apps can only do one thing at a

    time Wednesday, April 25, 12
  3. BAD Wednesday, April 25, 12

  4. 48(5< 5(48(67 '% 5(63216( Wednesday, April 25, 12

  5. 48(5< 5(48(67 '% 5(63216( Wednesday, April 25, 12

  6. DB Queries = Wasted Time Wednesday, April 25, 12

  7. Wednesday, April 25, 12

  8. Rails CAN do more than one thing at a time

    (since Rails 2.2) Wednesday, April 25, 12
  9. THREADS Wednesday, April 25, 12

  10. # Enable threaded mode # config.threadsafe! config/environments/production.rb Wednesday, April 25,

    12
  11. # Enable threaded mode config.threadsafe! config/environments/production.rb Wednesday, April 25, 12

  12. DONE Wednesday, April 25, 12

  13. Curious Suspicious How Rubyists See Threads Wednesday, April 25, 12

  14. “I don’t want to have to deal with concurrency” Wednesday,

    April 25, 12
  15. TOO LATE Wednesday, April 25, 12

  16. Concurrency: You’re already doing it User.transaction do ... end Wednesday,

    April 25, 12
  17. Your DB uses threads* Your app should too *If it

    doesn’t, it probably sucks Wednesday, April 25, 12
  18. '% One VM, Multiple Requests Wednesday, April 25, 12

  19. Won’t the GIL get in the way? Wednesday, April 25,

    12
  20. NO Wednesday, April 25, 12

  21. I/O automatically releases the GIL Wednesday, April 25, 12

  22. C extensions can release the GIL too Wednesday, April 25,

    12
  23. “Are my gems thread-safe?” Wednesday, April 25, 12

  24. Wednesday, April 25, 12

  25. lib/ can be a pain Eager Loading Wednesday, April 25,

    12
  26. class HerpDerper < ActiveRecord::Base include ThingFrobber end Wednesday, April 25,

    12
  27. app/models/herp_derper.rb:2:in `<class:HerpDerper>': uninitialized constant HerpDerper::ThingFrobber (NameError) from app/models/herp_derper.rb:1:in `<top (required)>'

    Wednesday, April 25, 12
  28. Wednesday, April 25, 12

  29. Wednesday, April 25, 12

  30. Require your dependencies with require_dependency Wednesday, April 25, 12

  31. require_dependency 'thing_frobber' class HerpDerper < ActiveRecord::Base include ThingFrobber end Wednesday,

    April 25, 12
  32. Wednesday, April 25, 12

  33. Multicore Wednesday, April 25, 12

  34. Multicore Is The Future Wednesday, April 25, 12

  35. AMD Bulldozer 1 CPU = 16 Cores Wednesday, April 25,

    12
  36. Why run N VMs when you could run just 1?

    Wednesday, April 25, 12
  37. •Higher Throughput •Pool Resources •Save Memory Threads are more efficient

    Wednesday, April 25, 12
  38. Rubinius Ruby without a GIL! Multicore parallelism! Wednesday, April 25,

    12
  39. My dream for Rails 4... Wednesday, April 25, 12

  40. # Enable threaded mode config.threadsafe! Thread Safe by Default Wednesday,

    April 25, 12
  41. Thanks! Wednesday, April 25, 12

  42. Twitter: @bascule Celluloid: celluloid.io Blog: unlimitednovelty.com Wednesday, April 25, 12