Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, January 24, 2013

Rspec matchers for Sidekiq

I've been writing a lot of specs lately to make sure my code properly enqueues Sidekiq jobs. I ended up duplicating a lot of code, and after reading the Rspec custom matcher documentation, I decided to DRY up the tests using some of my own matchers. The code is here in my "power tools" gem. Enjoy!

The tests end up looking like this:
  MyWorker.should have_queued_job(2)
  Collector.should have_queued_job_at(Time.new(2012,1,23,14,00),2)

Wednesday, October 31, 2012

Setting up Puma & Rails on Heroku

I just moved Adstaq over to Puma this weekend because I want to experiment with a multithreaded server as a way to keep our web serving costs down and our efficiency high. We're already doing this with Sidekiq for our worker code, to great effect, and philosophically I much prefer plain old Ruby threads over other Ruby concurrency solutions. Dave Copeland gave a GREAT talk at RubyConf last year called Don't Fear the Threads which I highly recommend for further inspiration.

It took some trial and error to get Rails talking to Puma and to get everything running on Heroku, so I put the needed code into a gist, embedded below.

I'm monitoring the change on New Relic but so far have not noticed any memory savings vs. Unicorn. But we're also not drowning in traffic right now. Nonetheless I'm glad we're getting some Rails multithreading experience before that happens.

Update: Watsi posted some great instructions for adjusting ActiveRecord's connection pool size.