drupal7+varnish: varnish总是miss的原因



最近发现不知什么原因,匿名用户访问的页面都返回varnish miss,这样造成后台的访问压力非常大。经过几天的debug,总算把问题解决了。下面是问题的总结。

[How to isolate the issue]

If you see the normal anonymous page, it’s HTTP Header always show ‘Cache-Control: public, max-age=xxx’, and can see ‘X-Cache:Hit’.

 

For the problem page, header will be ‘Cache-Control: no-cache,must-revalidate,post-check=0,pre-check=0’, also first access can see ‘Set-Cookie: SESSxxx=xxx’.

 

If drupal7 session cookie exists, following request will always miss cache.

 

[Reason]

For varnish, it depends on apache’s response to determine whether a request will be cached. If apache response header contains ‘Cache-Control: public max-age=xxx’, it will be cached for max-age. If header contains ‘Cache-Control: no-cache’, it will always pass the request to apache.

 

For anonymous user, drupal7 will not start session by default. This is for performance consideration. If session exists, drupal7 will always return no cache header and drop a session cookie.

 

But if any data put into $_SESSION, the user session will be started. Dive into the code, in common.inc, function drupal_page_footer will call session.inc’s function drupal_session_commit(). It will check if any data in $_SESSION then call drupal_session_start() to start a session.

If some errors in template, the error string will put into $_SESSION, then drupal7 will start the session.

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值