在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.html

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.app

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

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.memcached

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

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"):rest

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.code

Picture

相關文章
相關標籤/搜索