1

我在使用 symfony 2 时遇到了一个奇怪的问题。我有一个应用程序,上面有一个倒数计时器(倒数小时分钟和天数)。

这个一分钟一分钟的计时器在 90% 的时间里都能正常工作,但是当负载很重时,计时器会卡住并且不会改变(可能是因为它正在提供缓存版本):

我们无法使用负载测试脚本复制错误,它似乎只在站点上有很多实际用户时才会发生。

我们的缓存选项设置如下:

class AppCache extends HttpCache
{

   protected function getOptions()
   {
       return array(
           'debug'                  => true,
           'default_ttl'            => 1 * 60 * 60,
           'private_headers'        => array('Authorization', 'Cookie'),
           'allow_reload'           => false,
           'allow_revalidate'       => false,
           'stale_while_revalidate' => 2,
           'stale_if_error'         => 60,
       );
    }
}

偶尔缓存的响应具有以下标头:

HTTP/1.1 200 OK
Date: Fri, 17 May 2013 09:36:55 GMT
Server: Apache/2.2.16 (Debian)
X-Powered-By: PHP/5.3.3-7+squeeze15
P3P: CP="CURa CUR NID ADM ADMa DEV DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"
Cache-Control: private
X-Symfony-Cache: GET /my-app/show: miss
Vary: Accept-Encoding
Content-Encoding: gzip
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

我们的 Front Controller 脚本文件如下:

<?php header('P3P: CP="CURa CUR NID ADM ADMa DEV DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');


use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\ClassLoader\ApcClassLoader;


$loader = require_once __DIR__.'/app/bootstrap.php.cache';
require_once __DIR__.'/app/AppKernel.php';
require_once __DIR__.'/app/AppCache.php';

$loader = new ApcClassLoader('sf2', $loader);
$loader->register(true);



$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel = new AppCache($kernel);
Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request, $response);

除了我们使用 AppCache 来包装我们的内核这一事实之外,我们还没有在此操作上明确设置任何 http 缓存,或者设置任何要缓存的内容。这样做肯定会对我们网站的性能产生巨大影响,因为当我们关闭它时,负载测试期间负载会迅速上升。

4

0 回答 0