Scalable PHP with phpa, memcached and LVS (Part 1)

Standard

One of the major pitfalls of the PHP LAMP stack is that run-time compilation does not scale very well. An experienced developer would lament over PHP bloat and the other downfalls that come with the ease and convenience of using a scripting language as the foundation for your application.

Over the last month or so, I have been working on creating a better version of addons.mozilla.org (AMO). It is a task that I enjoy, mostly because it isn’t everyday you get the great opportunity to work on a project that touches so many people and means so much.

My journey is similar to the journey taken by Drupal, PHPBB or MediaWiki developers. Given a great PHP product, you not only have to fulfill usability requirements, you also have to make the thing work for an insanely large user base. In my journey I have found an appreciation for the delicate balance between usability/features/design and the pain of having to maintain them. It’s the line between being a designer or marketing droid and being a core developer and a sysadmin.

I’ve learned that, in any successful project, you need to have someone who understands both sides. If you don’t, you run the risk of having one of two things:

  • A great looking website that meets your users’ needs but doesn’t run and is not secure
  • A fast and secure web app that nobody uses

A successful project usually lands somewhere inbetween. It’s a compromise between the best performance and the usability and flexibility most people demand — albeit users or administrators.

So when you’re faced with circumventing PHP bloat, you go through predictable steps:

  • Try to run your site as-is, but then realize it fails miserably because of the database bottleneck
  • Duplicate your database, splitting it between read/write and read-only — add a slave or multiple slaves via RRDNS to serve the bits you need
  • When this fails, you start looking for output caching mechanisms that give your database a break
  • You then realize that full output caching is unrealistic because your cache hits are not high enough
  • You find yourself stuck, looking for answers — and you find ways to deliver features with the hardware you have, without making any large-scale app-level changes

When you’re at this point, there are two solutions:

  • Optimize PHP somehow to reduce redundant compilation between requests
  • Use some sort of granular caching to give your DB a break

In the next part of this post, I’ll talk about implementation of phpa/memcached across an LVS cluster and what a difference it made compared to altnernative solutions. I will post graphs explaining perf gains for AMO, and explain why we used phpa and memcached as the final solution.

Building scalable applications is challenging, but you’re not alone.

OSU Athletes Rule (in intramurals)

Standard

After stewing on this for a while, I realized my “beef” ranks down there with steroids in baseball, underwater basketweaving and having people swear an oath when they testify in front of the senate judiciary committee (sarcasm). I know — these aren’t the best wars to fight — but we should at least be aware of issues like these, because they are symptoms of a slightly more serious affliction.

When I question why varsity players are allowed to play in intramural games, it’s not a matter of me being upset about losing to a team full of varsity athletes (which I am, but that’s beside the point). I am more concerned with issues of accountibility, duty and fairness. These are issues that plague professional sports, our government, the media and our society in general — we have a problem with integrity. We don’t respect the rules, the law, or our duties. We’re teenagers away from home, and we’re flirting with danger.

When a varsity athlete is chosen to play for a collegiate team, they are binded in an agreement with the university — the donors, the fans, the coaches. They enter an agreement with all of us at OSU that covers things like drugs, skydiving, or riding motorcycles without a helmet. Altogether the idea is simple: don’t put yourself in a position to get hurt because you’re supposed to be playing for OSU, and OSU is relying on you.

It’s important for athletes to accept responsibility for this general rule. It is their duty to uphold their part of the bargain. It means being mature, responsible and held accountable for their safety. It means staying true to the mission a true NCAA athlete should have — to be the best student athletes they can be and represent their university.

I think it is obvious that playing in intramural sports is an unnecessary risk, and it crosses the line of accountibility and duty for any student athlete — particularly those on scholarships. They made a deal with the university to do a job, including taking care of their body and preparing themselves properly for upcoming seasons.

At OSU, intramural rules dictate that:

Varsity Athletes in Related Sports: Varsity athletes may participate in other intramural activities outside of their varsity sport. However, they may not participate in their varsity sport or its related activities at the intramural level. (i.e. football/flag football; baseball/softball; swimming/water polo).

I just don’t buy it. You have to take into account that NCAA athletes train at a much higher level than the weekend athlete, and their physical condition in terms of speed, quickness, endurance and strength are all much better than the average OSU student.

Plus, what happens when any varsity athlete breaks a leg or strains a muscle during an intramural game? I think they should get thrown off the team and lose their scholarship. This isn’t intermediate 7th grade sports, kids. These athletes get compensated tens of thousands for tuition, books, room and board, the works — they are compensated for the work they put into being great athletes.

I’m not sure what happens with their medical bills in case of in injury, either. If they aren’t already I think they should be held accountable for these costs, too.

On the other side of the coin, we have paying students, normal kids that don’t train at the level NCAA athletes train — mostly because they are busy working jobs to pay for tuition that can support an environment where student athletes get great scholarships. We have staff or faculty who work hard to contribute to the OSU community day in and day out and don’t have three hours a day to spend in the gym.

So what do we do to thank them?

We let NCAA athletes play in their intramural leagues and dominate them. We allow these same athletes the right to decide to put themselves in danger and jeopardize their ability to represent OSU. We pretty much let them do whatever they want.

Haven’t we had enough? At what point will OSU athletes start being held accountable to their obligations? Are we to the point where our OSU athletes are such a joke they can waste time playing in intramural leagues with people who are nowhere near as fast, big or strong as them?

To all the varsity athletes who played in intramurals this year — go train seriously, stop picking on the little people, and stand up and accept responsibility for your role in the OSU community. Go be the best athlete you can be and leave the intramural leagues alone.

Your place is in Gil or Reser, proudly wearing an OSU uniform — definitely not in a sweaty used jersey in Dixon playing against scrubs like me.

In most highschools, varsity players can’t play in intramural leagues. Sadly, OSU has a lot to learn from high schools.