comparison src/http/ngx_http_file_cache.c @ 3967:83e41f6f6d96

The cache loader performs two tasks: inserting cache objects in inactivity list and evaluating total cache size. Reading just directory is enough for this purpose. Elimination of reading cache files saves at least one disk I/O operation per file. Preparation for elimination of reading cache files by cache loader: removing dependencies on the reading: *) cache node valid_sec and valid_msec are used only for caching errors; *) upstream buffer size can be used instead of cache node body_start.
author Igor Sysoev <igor@sysoev.ru>
date Sun, 24 Jul 2011 16:47:31 +0000
parents 9c425f22ea36
children d7ed8b8b0cdd
comparison
equal deleted inserted replaced
3966:9c425f22ea36 3967:83e41f6f6d96
531 } 531 }
532 532
533 if (fcn->exists || fcn->uses >= c->min_uses) { 533 if (fcn->exists || fcn->uses >= c->min_uses) {
534 534
535 c->exists = fcn->exists; 535 c->exists = fcn->exists;
536 c->body_start = fcn->body_start; 536 if (c->body_start) {
537 c->body_start = fcn->body_start;
538 }
537 539
538 rc = NGX_OK; 540 rc = NGX_OK;
539 541
540 goto done; 542 goto done;
541 } 543 }
1363 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno, 1365 ngx_log_error(NGX_LOG_CRIT, ctx->log, ngx_errno,
1364 ngx_fd_info_n " \"%s\" failed", name->data); 1366 ngx_fd_info_n " \"%s\" failed", name->data);
1365 1367
1366 } else { 1368 } else {
1367 c.uniq = ngx_file_uniq(&fi); 1369 c.uniq = ngx_file_uniq(&fi);
1368 c.valid_sec = h.valid_sec;
1369 c.valid_msec = h.valid_msec;
1370 c.body_start = h.body_start;
1371 c.length = ngx_file_size(&fi); 1370 c.length = ngx_file_size(&fi);
1372 c.fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize; 1371 c.fs_size = (ngx_file_fs_size(&fi) + cache->bsize - 1) / cache->bsize;
1373 } 1372 }
1374 1373
1375 if (ngx_close_file(fd) == NGX_FILE_ERROR) { 1374 if (ngx_close_file(fd) == NGX_FILE_ERROR) {
1376 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno, 1375 ngx_log_error(NGX_LOG_ALERT, ctx->log, ngx_errno,
1377 ngx_close_file_n " \"%s\" failed", name->data); 1376 ngx_close_file_n " \"%s\" failed", name->data);
1378 }
1379
1380 if (c.body_start == 0) {
1381 return NGX_ERROR;
1382 } 1377 }
1383 1378
1384 p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN]; 1379 p = &name->data[name->len - 2 * NGX_HTTP_CACHE_KEY_LEN];
1385 1380
1386 for (i = 0; i < NGX_HTTP_CACHE_KEY_LEN; i++) { 1381 for (i = 0; i < NGX_HTTP_CACHE_KEY_LEN; i++) {
1424 1419
1425 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node); 1420 ngx_rbtree_insert(&cache->sh->rbtree, &fcn->node);
1426 1421
1427 fcn->uses = 1; 1422 fcn->uses = 1;
1428 fcn->count = 0; 1423 fcn->count = 0;
1429 fcn->valid_msec = c->valid_msec; 1424 fcn->valid_msec = 0;
1430 fcn->error = 0; 1425 fcn->error = 0;
1431 fcn->exists = 1; 1426 fcn->exists = 1;
1432 fcn->updating = 0; 1427 fcn->updating = 0;
1433 fcn->deleting = 0; 1428 fcn->deleting = 0;
1434 fcn->uniq = c->uniq; 1429 fcn->uniq = c->uniq;
1435 fcn->valid_sec = c->valid_sec; 1430 fcn->valid_sec = 0;
1436 fcn->body_start = c->body_start; 1431 fcn->body_start = 0;
1437 fcn->fs_size = c->fs_size; 1432 fcn->fs_size = c->fs_size;
1438 1433
1439 cache->sh->size += c->fs_size; 1434 cache->sh->size += c->fs_size;
1440 1435
1441 } else { 1436 } else {