Passenger

Posted by tobi — 01:14 PM Nov 15

So there is a lot of talk about Phusion Passenger lately and I feel the need to chime in here. David pointed out that Shopify is running on passenger which is something I announced on Twitter a few months ago.

Some context on Shopify’s installation: We launched Shopify originally on Lighttpd with FastCGI and later migrated to nginx with mongrels. Obviously we had to use HAProxy between Nginx and mongrels to avoid the dreaded “queue behind long running process” problem. We also added Monit to the mix which observed all mongrels to make sure that everything is running according to plan. After a process reaches 260 mb of memory we signal it to shut down after the next request so that a new one can start out with less memory. For this we added runit to the mix which supervises the mongrels and starts them up quickly once they hit the ground.

It’s important to note that we are not talking about a memory leak here. The reason for the 260mb ceiling comes from two issues with Ruby’s garbage collector:

  1. It allocates memory in very large chunks once the available memory gets low. This means a 140mb process increases to 260mb in a single go. It also never gives memory back to the operating system because Ruby’s GC is not able to move objects. Once it adds an object into the newly allocated space and that object remains alive, it cannot yield memory back to the OS.
  2. Because Ruby’s garbage collector uses mark and sweep it has to traverse the entire memory space in search of pointers. There are no generations that help with that. It means that GC cycles become longer and longer the more memory is available. -Rails mitigates these issues by moving a full GC run behind a HTTP response, into the time period when the process is waiting for a new request (Update: Rails doesn’t do this anymore) but performance monitoring tools such as NewRelic clearly show that average response times is directly correlated with the amount of memory used across the server farm.

Now why did we switch to Passenger? Simple: the keyword is remove moving parts.

Every additional tool you add will come with it’s own bugs. Many people I talked to over the past years considered haproxy to be the most solid piece of infrastructure in their stack but even there was a really nasty bug recently (search for request queue handling).

We treat our server farm very similar to Shopify’s codebase. We are in this for the long haul and we cannot accept complex solutions when simple ones present themselves. Maintainability of our code and servers is paramount to the long term success of our product. Yes the Mongrel setup worked very well but Passenger allowed us to remove: Nginx, Haproxy, Runit and Monit. That’s a nice refactoring!

At the same time Passenger introduced some tangible improvements. We switched to enterprise ruby to get the full benefit of the COW memory characteristics and we can absolutely confirm the memory savings of 30% some others have reported. This is many thousand dollars of savings even at today’s hardware prices. We allow Passenger to adaptively spawn more processes with demand but most of the time our application servers are running about 40 processes to handle more than a million dynamic requests a day. However, because passenger constantly despawns and respawns rails processes they always stay fresh, run short GC cycles and are generally a lot more responsive. All this means that the total amount of memory that is used by Shopify during normal operations went from average of 9GB to an average of 5GB. We evenly distributed the savings amongst more Shopify processes and more memcached space which moved our average response time from 210ms to 130ms while traffic grew 30% in the last few months.

In conclusion: I cannot see any reason to choose a different deployment strategy at this point. Its simple, complete, fast and well documented.

17 comments Filed under: Code Rails

Interview

Posted by tobi — 12:30 PM Nov 07

openvista posted their interview with me in which I talk about entrepreneurship and the early days of Shopify.

0 comments

Rockstar Memcaching (video)

Posted by tobi — 02:02 PM Oct 28

InfoQ posted the video to my rockstar memcaching presentation from ruby fringe.

Rockstar Memcaching Video

3 comments

Mobile Development

Posted by tobi — 06:08 PM Oct 23

I’ve been playing around with mobile development lately which is a nice change of pace. Before Shopify and Rails I used to count myself amongst the ranks of the C++ desktop developers ( go WTL!! ) so in many ways the concepts of mobile development feel like the good’ old times—without all the things that drive you up the walls.

What’s so fun about it is the innocence of it all. It’s the gold rush all over again. For example that bastard Hampton managed to sell his Wikipedia browser iPedia 50k times. Check out www.mobileorchard.com which just published an interview with him.

1 comment

LHC Rap

Posted by tobi — 01:28 PM Oct 11

via youtube

1 comment (closed)

Shopify Blogging

Posted by tobi — 02:41 PM Oct 06

Brand and community development where always the guiding principles behind Shopify and today we launched an important aspect of this: Your visitors can now comment on blog posts.

Read more about it on the shopify blog

We will provide an import tool for wordpress and other blogging systems soon (implemented as an open source shopify api app. )

0 comments (closed)

Liquid JS

Posted by tobi — 09:54 PM Aug 30

Color me impressed.

Matt Mccray ported Liquid to javascript. Go here to get the gist of it (yea, bad pun)

Pretty awesome work Matt :-)


<script>
 Liquid.readTemplateFile = function(path) {
  var elem = $(path);
  if(elem) {
    return elem.innerHTML;
  } else {
    path +" can't be found."; // Or throw and error, or whatever you want...
  }
 }

 var tmpl = Liquid.parse("{% include 'myOtherTemplate' with current_user %}"); 
 alert( tmpl.render({ current_user:'M@' }));
</script>

<script type="text/liquid" id="myOtherTemplate">
  Hello, {{ current_user }}!
</script>

2 comments (closed)

Competitor Comedy

Posted by tobi — 03:14 PM Aug 22

Shopify got profiled last week in Practical E-Commerce as cart of the week . According to them they found 300 different Shopping cart packages, I know our market was big but that’s pretty insane.

Anyways, their Cart of the Week feature pits one Cart against another by asking a competitor to comment on the software, CNN style. In our case they asked Rick Wilson of Miva Merchant to comment on Shopify. Here is what he dislikes:

The obvious weaknesses I saw were the limits on what they called ‘enterprise’ level offering of only 10,000 SKUs. The other major weakness is the product is built using Ruby On Rails. Ruby On Rails seems to be a development environment with a lot of future possibilities, but as a general rule you don’t want your revenue-generating product to be based on cutting edge technology. There’s a lot of unforeseeable pitfalls in that area.

(emphasis mine).

So to deconstruct the first part of this argument let me just say that we have millions of products in Shopify right now and it’s a pure business decision to limit SKUs to 10k and has nothing to do with the software. There are millions of products in the database. In fact i’d buy Rick lunch if Shopify isn’t right now handling twice the traffic any given Miva Merchant store has ever sustained.

What’s left is the advice that you shouldn’t run a revenue-generating web site based on cutting edge technology. I don’t think I have to point out how ridiculous that statement is. First of all I presume that perl was pretty cutting edge ( definitely more than ruby is today ) in 1998 when Miva was written and also we are talking about bloody Miva Merchant here, the e-commerce system that runs on a proprietary closed source database that is known for corruption issues after several hundred products. Not only that, it seems to be one of their main sources of revenue: For 129$ setup + 20$ a month you can get some support and basic database recovery. Unfortunately:

** Due to the nature of database problems not all database corruption can be covered under this package

Isn’t it nice that you never have to worry about such tactics with hosted systems and SaaS packages like Shopify?

4 comments (closed)

Rockstar Memcaching

Posted by tobi — 05:37 AM Jul 21

I’m back from Rubyfringe which was hands down the best conference i’ve been to.

Pete Forde asked me to present on memcached (mem-cache-dee) after my popular blog article Secret to memcached. The talk covers different use cases such as simple html snippet stores to advanced expiry systems such as generational cache keys.

Every talk at rubyfringe was taped so I’ll update this space with the video once its online. In the meantime enjoy the slides which probably make zero sense on their own.

Download the PDF or watch it on slideshare:

P.S: 30 minute is the ideal length for talks at a Tech Conference.

Update: The video was posted here

12 comments (closed)

Shopify Sys Admin

Posted by tobi — 03:41 PM Jul 07

If you love servers you should consider applying for our system administrator position . Flexible work hours and you get to work with all the coolest and latest technologies and a fantastic team.

0 comments (closed)

One million integers?!

Posted by tobi — 11:09 PM Jul 06

This is a great general purpose interview tip:

If you don’t know how to answer a question because it’s way outside of your expertise simply give it your best guess and negate the question.

via youtube:

This can sometimes have pretty impressive results.

1 comment (closed)

Gecko/Webkit Screenshots

Posted by tobi — 12:07 PM May 17

For our Shopify Product Search we needed a good way to Screenshot web pages. There are some services on the web for this but we ended up building it but none of them fit our needs. They were either way to expensive, they didn’t produce nearly the quality we needed or they didn’t offer an API at all.

Our solution was to install a headless X server in our server farm which runs firefox 2.0. We used a python GTK automation script which navigates the Firefox instance to the page and then dumps the framebuffer into a png file when done. This works well enough but i’d like something more robust for a different project.

Ideally I’d like someone to build a screenshot tool based on Gecko or Webkit which can simply take an url and spit out an png. A dependency on an running X server is acceptable but I’d rather not have it running all the time because it complicates deployment a lot. It has to run on Linux and must not depend on a shared global resource, i.e. you should be able to take two screenshots at the same time.

If you know of a tool like the one I describe or if you think you could build something like this for me please contact me. This may be paid open source work.

15 comments (closed)

Twitter

Posted by tobi — 09:13 PM May 08

I need more followers on twitter :-)

5 comments (closed)

Canadian Citizenship

Posted by tobi — 01:04 PM May 05

Today I got my Canadian citizenship.

Both Germany and Canada allow multiple citizenships so I’m allowed to carry both. Geographical redundancy accomplished. Next step is to apply for my Canadian passport so that I can instant failover :-)

Update: Take the citizenship test yourself and post your score in the comments.

21 comments (closed)

Database situps

Posted by tobi — 08:45 AM Apr 22

Todd Hoff in his love letter to Amazon’s SimpleDB

SimpleDB shifts work out of the database and onto programmers which is why the SimpleDB programming model sucks: it requires a lot more programming to do simple things. I’ll argue however that this is the kind of suckiness programmers like. Programmers like problems they can solve with more programming. We don’t even care how twisted and inelegant the code is because we can make it work. And as long as we can make it work we are happy.

I can’t think of what drove him to write this. This argument is directly contradicted by the success of Rails.

5 comments (closed)