在symfony2项目中100%提升doctrine的性能

Doctrine 2 has a full chapter devoted to caching but up until now we had never taken a look to it at ulabox.

The thing is that the chapter does not only speak about caching SQL results for some time - the result cache -, a type of cache we're currently not interested in, but caching metadata to improve Doctrine performance. The problem is that by default both caching the class metadata and executing the DQL transformation are done in each request, but they could be cached for the duration of your current deploy, so there's room for improvement.

The first cache you should modify is the query cache. The documentation is very clear about it:

It is highly recommended that in a production environment you cache the transformation of a DQL query to its SQL counterpart. It doesn’t make sense to do this parsing multiple times as it doesn’t change unless you alter the DQL query.

The second one is the metadata cache, that avoids having to parse class metadata coming from annotations, YAMLs or XML in each request.

The way to change these settings in Symfony 2 is simple. Just modify your app caching drivers configuration (here we're changing from the default value "array" to "apc", but you could also use "memcache", "memcached", "xcache" or "service"):

doctrine:
  orm:
    metadata_cache_driver: apc    query_cache_driver: apc

The result? We've improved up to 100% the performance of our most DB-intensive pages.

Picture



你可能感兴趣的:(在symfony2项目中100%提升doctrine的性能)