在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



转载于:https://my.oschina.net/imot/blog/219556

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值