apache2 - N个过期对象的数量很高。为什么? -(里面是我的varnishstat和default.vcl)

标签 apache2 varnish cache-control varnish-vcl

我有运行Varnich 2的apache2。我的可能是,即使我的缓存控制设置为1年, Varnish 仍然具有N个过期对象的负载 1971 。这是我的default.vcl,它显示我的设置任何提示吗?:

backend apache {
.host = "127.0.0.1";
.port = "8080";
}

sub vcl_recv {

if (req.http.Accept-Encoding) {
    if (req.url ~ "\.(jpg|png|gif|gz|tgz|bz2|tbz|mp3|ogg)$") {
        # No point in compressing these
        remove req.http.Accept-Encoding;
    } elsif (req.http.Accept-Encoding ~ "gzip") {
        set req.http.Accept-Encoding = "gzip";
    } elsif (req.http.Accept-Encoding ~ "deflate") {
        set req.http.Accept-Encoding = "deflate";
    } else {
        # unkown algorithm
        remove req.http.Accept-Encoding;
    }
}

 if (req.url ~ "\.(ico|png|gif|jpg|swf|css|js)$") {
    return(lookup);
 }
}

## Fetch
sub vcl_fetch {

# strip the cookie before the image is inserted into cache.
 if (req.url ~ "\.(ico|png|gif|jpg|swf|css|js)$") {
   unset beresp.http.set-cookie;
}

## Remove X-Forwarded-For header if exists.
        remove req.http.X-Forwarded-For;

## insert client IP address as X-Forwarded-For.
        set    req.http.X-Forwarded-For = req.http.rlnclientipaddr;

## Deliver the content
        return(deliver);
}

## Deliver
sub vcl_deliver {

## Clean header
        remove resp.http.X-Varnish;
        remove resp.http.Via;
    remove resp.http.Age;
        remove resp.http.X-Powered-By;

    if (obj.hits > 0) {
        set resp.http.X-Cache = "HIT";
    } else {
        set resp.http.X-Cache = "MISS";
    }

}

Varnishstat,这是我的输出:
client_conn              4165         0.26 Client connections accepted
client_drop                 1         0.00 Connection dropped, no sess/wrk
client_req               5036         0.31 Client requests received
cache_hit                1235         0.08 Cache hits
cache_hitpass               0         0.00 Cache hits for pass
cache_miss               2329         0.14 Cache misses
backend_conn             1359         0.08 Backend conn. success
backend_unhealthy            0         0.00 Backend conn. not attempted
backend_busy                0         0.00 Backend conn. too many
backend_fail                0         0.00 Backend conn. failures
backend_reuse            2442         0.15 Backend conn. reuses
backend_toolate          1223         0.08 Backend conn. was closed
backend_recycle          3666         0.23 Backend conn. recycles
backend_unused              0         0.00 Backend conn. unused
fetch_head                  0         0.00 Fetch head
fetch_length             3665         0.23 Fetch with Length
fetch_chunked              51         0.00 Fetch chunked
fetch_eof                   0         0.00 Fetch EOF
fetch_bad                   0         0.00 Fetch had bad headers
fetch_close                67         0.00 Fetch wanted close
fetch_oldhttp               0         0.00 Fetch pre HTTP/1.1 closed
fetch_zero                 15         0.00 Fetch zero len
fetch_failed                0         0.00 Fetch failed
n_sess_mem                 30          .   N struct sess_mem
n_sess                      0          .   N struct sess
n_object                  314          .   N struct object
n_vampireobject             0          .   N unresurrected objects
n_objectcore              318          .   N struct objectcore
n_objecthead              361          .   N struct objecthead
n_smf                       0          .   N struct smf
n_smf_frag                  0          .   N small free smf
n_smf_large                 0          .   N large free smf
n_vbe_conn                  1          .   N struct vbe_conn
n_wrk                      10          .   N worker threads
n_wrk_create               10         0.00 N worker threads created
n_wrk_failed                0         0.00 N worker threads not created
n_wrk_max              567851        35.17 N worker threads limited
n_wrk_queue                 0         0.00 N queued work requests
n_wrk_overflow             37         0.00 N overflowed work requests
n_wrk_drop                  4         0.00 N dropped work requests
n_backend                   1          .   N backends
n_expired                1971          .   N expired objects
n_lru_nuked                 0          .   N LRU nuked objects
n_lru_saved                 0          .   N LRU saved objects
n_lru_moved              1211          .   N LRU moved objects
n_deathrow                  0          .   N objects on deathrow
losthdr                     0         0.00 HTTP header overflows
n_objsendfile               0         0.00 Objects sent with sendfile
n_objwrite               4810         0.30 Objects sent with write
n_objoverflow               0         0.00 Objects overflowing workspace
s_sess                   4164         0.26 Total Sessions
s_req                    5036         0.31 Total Requests
s_pipe                      0         0.00 Total pipe
s_pass                   1472         0.09 Total pass
s_fetch                  3798         0.24 Total fetch
s_hdrbytes            1925358       119.25 Total header bytes
s_bodybytes         111698308      6918.45 Total body bytes
sess_closed              2172         0.13 Session Closed
sess_pipeline               0         0.00 Session Pipeline
sess_readahead              0         0.00 Session Read Ahead
sess_linger              3290         0.20 Session Linger
sess_herd                3093         0.19 Session herd
shm_records            343107        21.25 SHM records
shm_writes              40917         2.53 SHM writes
shm_flushes                 0         0.00 SHM flushes due to overflow
shm_cont                    3         0.00 SHM MTX contention
shm_cycles                  0         0.00 SHM cycles through buffer
sm_nreq                     0         0.00 allocator requests
sm_nobj                     0          .   outstanding allocations
sm_balloc                   0          .   bytes allocated
sm_bfree                    0          .   bytes free
sma_nreq                 6015         0.37 SMA allocator requests
sma_nobj                  627          .   SMA outstanding allocations
sma_nbytes            4035862          .   SMA outstanding bytes
sma_balloc           34755299          .   SMA bytes allocated
sma_bfree            30719437          .   SMA bytes free
sms_nreq                    3         0.00 SMS allocator requests
sms_nobj                    0          .   SMS outstanding allocations
sms_nbytes                  0          .   SMS outstanding bytes
sms_balloc               1464          .   SMS bytes allocated
sms_bfree                1464          .   SMS bytes freed
backend_req              3801         0.24 Backend requests made
n_vcl                       1         0.00 N vcl total
n_vcl_avail                 1         0.00 N vcl available
n_vcl_discard               0         0.00 N vcl discarded
n_purge                     1          .   N total active purges
n_purge_add                 1         0.00 N new purges added
n_purge_retire              0         0.00 N old purges deleted
n_purge_obj_test            0         0.00 N objects tested
n_purge_re_test             0         0.00 N regexps tested against
n_purge_dups                0         0.00 N duplicate purges removed
hcb_nolock               1245         0.08 HCB Lookups without lock
hcb_lock                    0         0.00 HCB Lookups with lock
hcb_insert               2319         0.14 HCB Inserts
esi_parse                   0         0.00 Objects ESI parsed (unlock)
esi_errors                  0         0.00 ESI parse errors (unlock)
accept_fail                 0         0.00 Accept failures
client_drop_late            3         0.00 Connection dropped late
uptime                  16145         1.00 Client uptime

如果有帮助,这就是我在apache2 conf中设置cache-control的方式:
<FilesMatch "\.(ico|pdf|gif|jpg|jpeg|png|swf|js|css)$">
ExpiresActive On
ExpiresDefault A31556926
Header unset ETag
FileETag None
</FilesMatch>

无法弄清楚为什么我的N个过期对象太高了?

最佳答案

通过添加以下内容,我已完全解决此问题:

set beresp.ttl = 31556926s;

在此之后添加
sub vcl_fetch { 

现在我有零个过期的对象,命中率提高了一倍!

我的最后一个 Unresolved 问题是...
N LRU moved objects

但是由于我在varnishstat中没有LRU裸体条目,因此事情似乎按预期进行了。

关于apache2 - N个过期对象的数量很高。为什么? -(里面是我的varnishstat和default.vcl),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8018079/

相关文章:

express - etag 如何在 expressjs 中工作

svn - 使用DAV SVN时如何正常渲染index.html?

django - 使用 mod_wsgi 在 Apache2 上部署 Django - Django 项目的正确位置?

javascript - codeigniter auth(Tank Auth) 无缘无故地将我注销(即可能是过载)

Symfony2和Varnish-了解其工作原理

windows - Windows Server 的 Varnish 替代品

javascript - 缓存文件直到下一页加载

javascript - 获取缓存响应 - 无缓存 header 未按预期工作

php - $_SERVER ['QUERY_STRING' ] 在 CodeIgniter 中不起作用

caching - 根据自定义 header 进行 Varnish 缓存