Scriptorama.nl

Header image showing a keyboard, mouse, laptop and books on design patterns

Performance overwegingen voor AMO

Mike Morgan is een van de ontwikkelaars die heeft gewerkt aan een performance rewrite van http://addons.mozilla.org of kort gezegd AMO. Deze site heeft nogal In 2 artikelen beschrijft hij welke problemen ze zijn tegen gekomen en welke dingen een slecht idee zijn als je pure performance nodig hebt.


Scalable PHP with APC, memcached and LVS (Part 1)
Scalable PHP with APC, memcached and LVS (Part 2)

Als advies geeft Mike vooral aan om niet te snel naar grote libraries als Smarty en PEAR::DB te grijpen als het niet echt hoeft.

  • Ask yourself if you really need DB layer abstraction. DBI’s are great, but hey are also huge. PEAR::DB is massive, and if your app isn’t going to be ported to other RDBMS’s, then you should really consider using your own wrapper for the mysql/mysqli functions built-in to PHP. In my experience, people hardly ever switch their DB layer over, and even if they did, if you write a clear and concise DB class, it is easy to switch out anyway. Abstraction here isn’t worth the overhead.
  • Ask yourself if you really need a template language with more rules and more syntax to mess up. PHP itself is a scripting language made to write web pages — so how much sense does Smarty make? Having been down the Smarty path, I’ve given it a shot, and I don’t think it’s worth it to replicate everything PHP does. If you’re doing it for design purposes, PHP syntax is already pretty simple, and most WYSIWYG editors have built-in escaping/tokenization for PHP’s syntax. If you’re using Smarty for separation of your view component, you can do the same thing in just PHP using app logic. And if you’re doing it so you can cache or precompile output, you’re just duplicating what memcached and APC would already offer you. If we could do it again, Smarty would not be worth the performance loss. So be wary of templating languages in such a high-level language. It’s usually a lose-lose.

Verder raadt hij het gebruik van memcached en APC aan.

APC is een bytecode cache die "gecompileerde" PHP bestanden (de PHP bestanden in bytecode vorm) opslaat in bijvoorbeeld het geheugen zodat de volgende aanvraag die bij de webserver binnen komt gebruik kan maken van deze bytecode vorm en dus niet de bestanden nogmaals hoeft te parsen. De code kan direct door Zend Engine worden uitgevoerd.

memcached is een caching systeem dat voornamelijk lijsten van gegevens kan op slaan. Denk aan de associatieve arrays die PHP biedt. Doordat deze applicatie op zich zelf staat en netwerk connecties accepteert kunnen meerdere servers, zoals het geval is bij AMO, gebruik maken van dezelfde cache. Werk je maar met 1 server, dan zou je ook gewoon de cache functionaliteit die APC biedt kunnen gebruiken.

Reageer ook!

Leave a comment
Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>