[Groonga-commit] groonga/groonga at ea5c2c3 [master] groonga-httpd: add groonga_cache_limit configuration

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Aug 23 13:52:57 JST 2013


Kouhei Sutou	2013-08-23 13:52:57 +0900 (Fri, 23 Aug 2013)

  New Revision: ea5c2c3d3600efb57647fe4fd0189e575b0a5a3b
  https://github.com/groonga/groonga/commit/ea5c2c3d3600efb57647fe4fd0189e575b0a5a3b

  Message:
    groonga-httpd: add groonga_cache_limit configuration
    
    It causes the same effect as
    http://localhost:10041/d/cache_limit?max=XXX.
    
    NOTE: Groonga's cache is shared in a process. So cache_limit can be
    set in worker unit not database unit. If you want to set cache_limit
    for each database, use the different nginx master.
    
    TODO: It should be documented.

  Modified files:
    data/groonga-httpd.conf.in
    src/httpd/nginx-module/ngx_http_groonga_module.c

  Modified: data/groonga-httpd.conf.in (+4 -0)
===================================================================
--- data/groonga-httpd.conf.in    2013-08-23 13:41:53 +0900 (13092cd)
+++ data/groonga-httpd.conf.in    2013-08-23 13:52:57 +0900 (9e95944)
@@ -26,6 +26,10 @@ http {
   # groonga-httpd, you should do it.
   groonga_database_auto_create on;
 
+  # The default groonga cache limit. The cache limit can be set
+  # for each worker. It can't be set for each groonga database.
+  # groonga_cache_limit 100;
+
   server {
     listen 10041;
     server_name localhost;

  Modified: src/httpd/nginx-module/ngx_http_groonga_module.c (+31 -0)
===================================================================
--- src/httpd/nginx-module/ngx_http_groonga_module.c    2013-08-23 13:41:53 +0900 (085aad6)
+++ src/httpd/nginx-module/ngx_http_groonga_module.c    2013-08-23 13:52:57 +0900 (5e7d753)
@@ -37,6 +37,7 @@ typedef struct {
   ngx_str_t log_path;
   ngx_open_file_t *log_file;
   grn_log_level log_level;
+  size_t cache_limit;
   char *config_file;
   int config_line;
   char *name;
@@ -806,6 +807,7 @@ ngx_http_groonga_create_loc_conf(ngx_conf_t *cf)
   conf->log_path.len = 0;
   conf->log_file = NULL;
   conf->log_level = GRN_LOG_DEFAULT_LEVEL;
+  conf->cache_limit = NGX_CONF_UNSET_SIZE;
   conf->config_file = NULL;
   conf->config_line = 0;
 
@@ -819,6 +821,9 @@ ngx_http_groonga_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
   ngx_http_groonga_loc_conf_t *conf = child;
 
   ngx_conf_merge_str_value(conf->database_path, prev->database_path, NULL);
+  ngx_conf_merge_size_value(conf->cache_limit, prev->cache_limit,
+                            GRN_CACHE_DEFAULT_MAX_N_ENTRIES);
+
 #ifdef NGX_HTTP_GROONGA_LOG_PATH
   {
     ngx_str_t default_log_path;
@@ -891,6 +896,20 @@ ngx_http_groonga_each_loc_conf(ngx_http_conf_ctx_t *http_conf,
   }
 }
 
+static void
+ngx_http_groonga_set_cache_limit(ngx_http_groonga_loc_conf_t *location_conf,
+                                 void *user_data)
+{
+  unsigned int *max_n_cache_entries;
+
+  if (location_conf->cache_limit == NGX_CONF_UNSET_SIZE) {
+    return;
+  }
+
+  max_n_cache_entries = grn_cache_max_nentries();
+  *max_n_cache_entries = location_conf->cache_limit;
+}
+
 static ngx_int_t
 ngx_http_groonga_mkdir_p(ngx_log_t *log, const char *dir_name)
 {
@@ -1023,6 +1042,11 @@ ngx_http_groonga_init_process(ngx_cycle_t *cycle)
 
   http_conf =
     (ngx_http_conf_ctx_t *)ngx_get_conf(cycle->conf_ctx, ngx_http_module);
+
+  ngx_http_groonga_each_loc_conf(http_conf,
+                                 ngx_http_groonga_set_cache_limit,
+                                 NULL);
+
   data.log = cycle->log;
   data.pool = cycle->pool;
   data.rc = NGX_OK;
@@ -1096,6 +1120,13 @@ static ngx_command_t ngx_http_groonga_commands[] = {
     0,
     NULL },
 
+  { ngx_string("groonga_cache_limit"),
+    NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
+    ngx_conf_set_size_slot,
+    NGX_HTTP_LOC_CONF_OFFSET,
+    offsetof(ngx_http_groonga_loc_conf_t, cache_limit),
+    NULL },
+
   ngx_null_command
 };
 
-------------- next part --------------
HTML����������������������������...
下載 



More information about the Groonga-commit mailing list
Back to archive index