comparison src/http/ngx_http_file_cache.c @ 4018:5e544655d97b

The change in adaptive loader behaviour introduced in r3975: now cache loader processes either as many files as specified by loader_files or works no more than time specified by loader_threshold during each iteration. loader_threshold was previously used to decrease loader_files or to increase loader_timeout and this might eventually result in downgrading loader_files to 1 and increasing loader_timeout to large values causing loading cache for forever.
author Igor Sysoev <igor@sysoev.ru>
date Mon, 22 Aug 2011 10:16:49 +0000
parents d10bcb07d9d4
children e2c075e774b6
comparison
equal deleted inserted replaced
4017:4f4086cf1a07 4018:5e544655d97b
28 static void ngx_http_file_cache_cleanup(void *data); 28 static void ngx_http_file_cache_cleanup(void *data);
29 static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache); 29 static time_t ngx_http_file_cache_forced_expire(ngx_http_file_cache_t *cache);
30 static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache); 30 static time_t ngx_http_file_cache_expire(ngx_http_file_cache_t *cache);
31 static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache, 31 static void ngx_http_file_cache_delete(ngx_http_file_cache_t *cache,
32 ngx_queue_t *q, u_char *name); 32 ngx_queue_t *q, u_char *name);
33 static ngx_int_t 33 static void ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
34 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache);
35 static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, 34 static ngx_int_t ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx,
36 ngx_str_t *path); 35 ngx_str_t *path);
37 static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, 36 static ngx_int_t ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx,
38 ngx_str_t *path); 37 ngx_str_t *path);
39 static ngx_int_t ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, 38 static ngx_int_t ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx,
1259 cache->bsize); 1258 cache->bsize);
1260 } 1259 }
1261 1260
1262 1261
1263 static ngx_int_t 1262 static ngx_int_t
1264 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache) 1263 ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1265 { 1264 {
1266 ngx_msec_t elapsed; 1265 return NGX_OK;
1266 }
1267
1268
1269 static ngx_int_t
1270 ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path)
1271 {
1272 ngx_msec_t elapsed;
1273 ngx_http_file_cache_t *cache;
1274
1275 cache = ctx->data;
1276
1277 if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
1278 (void) ngx_http_file_cache_delete_file(ctx, path);
1279 }
1267 1280
1268 if (++cache->files >= cache->loader_files) { 1281 if (++cache->files >= cache->loader_files) {
1269 1282 ngx_http_file_cache_loader_sleep(cache);
1283
1284 } else {
1270 ngx_time_update(); 1285 ngx_time_update();
1271 1286
1272 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last)); 1287 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last));
1273 1288
1274 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, 1289 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0,
1275 "http file cache loader time elapsed: %M", elapsed); 1290 "http file cache loader time elapsed: %M", elapsed);
1276 1291
1277 if (elapsed >= cache->loader_threshold) { 1292 if (elapsed >= cache->loader_threshold) {
1278 1293 ngx_http_file_cache_loader_sleep(cache);
1279 if (cache->loader_files > 1) { 1294 }
1280 cache->loader_files /= 2;
1281 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
1282 "cache %V loader_files decreased to %ui",
1283 &cache->path->name, cache->loader_files);
1284
1285 } else {
1286 cache->loader_sleep *= 2;
1287 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0,
1288 "cache %V loader_sleep increased to %Mms",
1289 &cache->path->name, cache->loader_sleep);
1290 }
1291 }
1292
1293 ngx_msleep(cache->loader_sleep);
1294
1295 ngx_time_update();
1296
1297 cache->last = ngx_current_msec;
1298 cache->files = 0;
1299 } 1295 }
1300 1296
1301 return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK; 1297 return (ngx_quit || ngx_terminate) ? NGX_ABORT : NGX_OK;
1302 } 1298 }
1303 1299
1304 1300
1305 static ngx_int_t 1301 static void
1306 ngx_http_file_cache_noop(ngx_tree_ctx_t *ctx, ngx_str_t *path) 1302 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache)
1307 { 1303 {
1308 return NGX_OK; 1304 ngx_msleep(cache->loader_sleep);
1309 } 1305
1310 1306 ngx_time_update();
1311 1307
1312 static ngx_int_t 1308 cache->last = ngx_current_msec;
1313 ngx_http_file_cache_manage_file(ngx_tree_ctx_t *ctx, ngx_str_t *path) 1309 cache->files = 0;
1314 {
1315 ngx_http_file_cache_t *cache;
1316
1317 cache = ctx->data;
1318
1319 if (ngx_http_file_cache_add_file(ctx, path) != NGX_OK) {
1320 (void) ngx_http_file_cache_delete_file(ctx, path);
1321 }
1322
1323 return ngx_http_file_cache_loader_sleep(cache);
1324 } 1310 }
1325 1311
1326 1312
1327 static ngx_int_t 1313 static ngx_int_t
1328 ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name) 1314 ngx_http_file_cache_add_file(ngx_tree_ctx_t *ctx, ngx_str_t *name)