Monthly Archives: May 2015

Optimizing Slim Routing

PHP image courtesy of flickr user stethoscopeis a general purpose programming language–but it acts a little differently than most (Ruby, Java, etc.) when used as a plugin to your web server. A Ruby on Rails app starts up and loads a bunch of things into memory and continues to run, but an Apache+PHP application is constantly dumping your PHP code and re-starting everything for every web request. Thus, while you can have a lengthy startup time in Rails and it’s totally cool, you must optimize your PHP code to do as little as possible all the time to keep it fast. This means keeping careful track of how your code loads up all of its dependencies–and not all PHP web frameworks do this elegantly.

Here at RealSelf, we do continuous integration and rapid deployment, and we iterate on things quickly. Sometimes code that starts out as an experiment turns into a key component of our infrastructure–even if its architecture wasn’t initially optimized for performance! So when we chose Slim to iterate quickly on a new API service, we got something up really quickly, and then slowly watched it grow in importance and response times. Recently, this situation became untenable as server response times grew to >300ms per request. We are getting between 1-3000 requests per minute for this particular service and end-users were starting to see the effects. Luckily, there was a simple solution to get around Slim’s deficiencies.

We discovered that each single route that we registered added a significant overhead to each request. As an experiment, we doubled the number of routes registered, and saw that we roughly doubled the response time of the server. Ouch! This service has a rather large API, so the number of registrations is significant here. Since this is a PHP app served by Apache, we quickly realized that we really don’t need 99% of these routes registered on a given request: Apache already knows which route was requested when it starts executing the PHP code, and PHP exposes this information in the $_SERVER['REQUEST_URI'] bucket. So, we really only need to register ONE route with the Slim framework. Nice.

We parsed out the REQUEST_URI and made a little registration routine that selects only the specific section of code concerned with registering that route, and the results were dramatic:

We shaved ~250 milliseconds off of our request time, bringing most requests under the ~100ms line. Notably, PHP is _still_ taking about 85% of the total request time, so clearly there are more optimizations to do. We should be able to get our response below 50ms. Really, all PHP needs to do is load some extremely targeted business logic (usually not even any logic, just a database query) and then turn that into a JSON payload to hand back to Apache. If we’re doing anything else, it’d better be for a really good reason!

It’s worth noting, however, that in other languages this wouldn’t be an issue at all. A Java web server would load all of this overhead up on app startup and code would be loaded, unloaded, and garbage-collected whenever the JVM sees the need. PHP is a very different beast, and needs to be treated very differently.

Defining the Damn Data

jenm-pro-headshot_largeAs a UX designer here at RealSelf, I collaborate with a larger team of product managers, developers, other designers and analysts (among others) to help create the best possible product features for our users. So I was excited to get the opportunity to share our design process with a larger audience, as one of the many speakers at the annual IA Summit, held last month in Minneapolis, MN. Each year at the IAS, information architects, user experience designers and content strategists come together to learn from each other and help advance our shared disciplines.

My talk, Defining the Damn Data, focused on how we use data at RealSelf to help inform product and design decisions every step of the way, from prioritizing features to validating specific designs with our users. While a podcast with audio will be posted shortly, for now you can view my slides to take a peek into our evolving process.

Jen Matson

Tom Seery, RealSelf CEO, Talks Creative Culture at IN-NW

Our CEO, Tom Seery, joined an impressive lineup onstage at the recent IN-NW: Digital Innovation + Leadership Conference. Moderated by Hanson Hosein, Director of Communication Leadership at UW CommLead, the panel also included UX Designer Olen Ronning of Artefact and Susan Howe, President of Global Consumer Marketing at Weber Shandwick. As they explored what it means to build a culture of creativity, the conversation ranged from how technology sparks creative ideas to the fact that we can’t expect just one person or team to lead the creativity revolution: creative cultures need contributions from everyone.

Thanks to the team at IN-NW for including RealSelf!