Mercurial > hg > nginx
comparison src/http/ngx_http_file_cache.c @ 3974:d10bcb07d9d4
loader_files, loader_sleep, and loader_threshold
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Fri, 29 Jul 2011 15:09:02 +0000 |
parents | 9d6f21415231 |
children | 5e544655d97b |
comparison
equal
deleted
inserted
replaced
3973:9d6f21415231 | 3974:d10bcb07d9d4 |
---|---|
1263 static ngx_int_t | 1263 static ngx_int_t |
1264 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache) | 1264 ngx_http_file_cache_loader_sleep(ngx_http_file_cache_t *cache) |
1265 { | 1265 { |
1266 ngx_msec_t elapsed; | 1266 ngx_msec_t elapsed; |
1267 | 1267 |
1268 if (cache->files++ > 100) { | 1268 if (++cache->files >= cache->loader_files) { |
1269 | 1269 |
1270 ngx_time_update(); | 1270 ngx_time_update(); |
1271 | 1271 |
1272 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last)); | 1272 elapsed = ngx_abs((ngx_msec_int_t) (ngx_current_msec - cache->last)); |
1273 | 1273 |
1274 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, | 1274 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ngx_cycle->log, 0, |
1275 "http file cache manager time: %M", elapsed); | 1275 "http file cache loader time elapsed: %M", elapsed); |
1276 | 1276 |
1277 if (elapsed > 200) { | 1277 if (elapsed >= cache->loader_threshold) { |
1278 | 1278 |
1279 /* | 1279 if (cache->loader_files > 1) { |
1280 * if processing 100 files takes more than 200ms, | 1280 cache->loader_files /= 2; |
1281 * it seems that many operations require disk i/o, | 1281 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
1282 * therefore sleep 200ms | 1282 "cache %V loader_files decreased to %ui", |
1283 */ | 1283 &cache->path->name, cache->loader_files); |
1284 | 1284 |
1285 ngx_msleep(200); | 1285 } else { |
1286 | 1286 cache->loader_sleep *= 2; |
1287 ngx_time_update(); | 1287 ngx_log_error(NGX_LOG_NOTICE, ngx_cycle->log, 0, |
1288 } | 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(); | |
1289 | 1296 |
1290 cache->last = ngx_current_msec; | 1297 cache->last = ngx_current_msec; |
1291 cache->files = 0; | 1298 cache->files = 0; |
1292 } | 1299 } |
1293 | 1300 |
1460 off_t max_size; | 1467 off_t max_size; |
1461 u_char *last, *p; | 1468 u_char *last, *p; |
1462 time_t inactive; | 1469 time_t inactive; |
1463 ssize_t size; | 1470 ssize_t size; |
1464 ngx_str_t s, name, *value; | 1471 ngx_str_t s, name, *value; |
1472 ngx_int_t loader_files, loader_sleep, loader_threshold; | |
1465 ngx_uint_t i, n; | 1473 ngx_uint_t i, n; |
1466 ngx_http_file_cache_t *cache; | 1474 ngx_http_file_cache_t *cache; |
1467 | 1475 |
1468 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t)); | 1476 cache = ngx_pcalloc(cf->pool, sizeof(ngx_http_file_cache_t)); |
1469 if (cache == NULL) { | 1477 if (cache == NULL) { |
1474 if (cache->path == NULL) { | 1482 if (cache->path == NULL) { |
1475 return NGX_CONF_ERROR; | 1483 return NGX_CONF_ERROR; |
1476 } | 1484 } |
1477 | 1485 |
1478 inactive = 600; | 1486 inactive = 600; |
1487 loader_files = 100; | |
1488 loader_sleep = 50; | |
1489 loader_threshold = 200; | |
1479 | 1490 |
1480 name.len = 0; | 1491 name.len = 0; |
1481 size = 0; | 1492 size = 0; |
1482 max_size = NGX_MAX_OFF_T_VALUE; | 1493 max_size = NGX_MAX_OFF_T_VALUE; |
1483 | 1494 |
1587 } | 1598 } |
1588 | 1599 |
1589 continue; | 1600 continue; |
1590 } | 1601 } |
1591 | 1602 |
1603 if (ngx_strncmp(value[i].data, "loader_files=", 13) == 0) { | |
1604 | |
1605 loader_files = ngx_atoi(value[i].data + 13, value[i].len - 13); | |
1606 if (loader_files == NGX_ERROR) { | |
1607 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1608 "invalid loader_files value \"%V\"", &value[i]); | |
1609 return NGX_CONF_ERROR; | |
1610 } | |
1611 | |
1612 continue; | |
1613 } | |
1614 | |
1615 if (ngx_strncmp(value[i].data, "loader_sleep=", 13) == 0) { | |
1616 | |
1617 s.len = value[i].len - 13; | |
1618 s.data = value[i].data + 13; | |
1619 | |
1620 loader_sleep = ngx_parse_time(&s, 0); | |
1621 if (loader_sleep < 0) { | |
1622 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1623 "invalid loader_sleep value \"%V\"", &value[i]); | |
1624 return NGX_CONF_ERROR; | |
1625 } | |
1626 | |
1627 continue; | |
1628 } | |
1629 | |
1630 if (ngx_strncmp(value[i].data, "loader_threshold=", 17) == 0) { | |
1631 | |
1632 s.len = value[i].len - 17; | |
1633 s.data = value[i].data + 17; | |
1634 | |
1635 loader_threshold = ngx_parse_time(&s, 0); | |
1636 if (loader_threshold < 0) { | |
1637 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1638 "invalid loader_threshold value \"%V\"", &value[i]); | |
1639 return NGX_CONF_ERROR; | |
1640 } | |
1641 | |
1642 continue; | |
1643 } | |
1644 | |
1592 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | 1645 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, |
1593 "invalid parameter \"%V\"", &value[i]); | 1646 "invalid parameter \"%V\"", &value[i]); |
1594 return NGX_CONF_ERROR; | 1647 return NGX_CONF_ERROR; |
1595 } | 1648 } |
1596 | 1649 |
1604 cache->path->manager = ngx_http_file_cache_manager; | 1657 cache->path->manager = ngx_http_file_cache_manager; |
1605 cache->path->loader = ngx_http_file_cache_loader; | 1658 cache->path->loader = ngx_http_file_cache_loader; |
1606 cache->path->data = cache; | 1659 cache->path->data = cache; |
1607 cache->path->conf_file = cf->conf_file->file.name.data; | 1660 cache->path->conf_file = cf->conf_file->file.name.data; |
1608 cache->path->line = cf->conf_file->line; | 1661 cache->path->line = cf->conf_file->line; |
1662 cache->loader_files = loader_files; | |
1663 cache->loader_sleep = (ngx_msec_t) loader_sleep; | |
1664 cache->loader_threshold = (ngx_msec_t) loader_threshold; | |
1609 | 1665 |
1610 if (ngx_add_path(cf, &cache->path) != NGX_OK) { | 1666 if (ngx_add_path(cf, &cache->path) != NGX_OK) { |
1611 return NGX_CONF_ERROR; | 1667 return NGX_CONF_ERROR; |
1612 } | 1668 } |
1613 | 1669 |