On 11.11.2011 02:16, Rainer Jung wrote:
I did a few lua tests and currently the reuse of lua states does not
work. Unfortunately I don't yet see the root cause.

We are constantly creating new lua states, saving them to the pool and
on the next request retrieve null and create a new state. When the
server is shutdown, all of the states are cleaned up together. This is
true for conn and thread scope and for prefork, worker and event. I'm
using apr trunk.

More info ahead: the pool we were using was the request pool, even when using scope conn or thread.

The note about all cleanups running at shutdown was a red herring due to missing flush in added debug output.

Why is it the request pool?

1) Because I used a handler defined inline in the config
   (as a LuaQuickHandler) the code use r->pool fixed. See Patch below.

2) Because I had the "LuaScope" directive below the <LuaQuickHandler>
   container. Needs to move before! Should order matter?

Rough performance result: Serving 2 Bytes via event before the patch lua was about 40% of the request throughput than serving a static file. After the patch lua content in quick handler is about 3 times as fast as static files. Both tests with a pretty small set of loaded modules and access log off. When moving lua to a normal handler via AddHandler I still get about twice the request throughput with lua compared to static files. Next would be to check how big the overhead of calling into lua is, e.g. comparing a fast static setup with static plus a few lines of lua in a hook.

Regards,

Rainer

@@ -171,6 +171,7 @@
 static int lua_request_rec_hook_harness(request_rec *r, const char *name, int apr_hook_when)
 {
     int rc;
+    apr_pool_t *pool;
     lua_State *L;
     ap_lua_vm_spec *spec;
     ap_lua_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
@@ -203,8 +204,26 @@

             apr_filepath_merge(&spec->file, server_cfg->root_path,
                                spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
-            L = ap_lua_get_lua_state(r->pool, spec);

+            switch (spec->scope) {
+            case AP_LUA_SCOPE_ONCE:
+             apr_pool_create(&pool, r->pool);
+              break;
+            case AP_LUA_SCOPE_REQUEST:
+              pool = r->pool;
+              break;
+            case AP_LUA_SCOPE_CONN:
+              pool = r->connection->pool;
+              break;
+            case AP_LUA_SCOPE_THREAD:
+              #if APR_HAS_THREADS
+              pool = apr_thread_pool_get(r->connection->current_thread);
+              break;
+              #endif
+            }
+
+            L = ap_lua_get_lua_state(pool, spec);
+
             if (!L) {
                 ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
                               "lua: Failed to obtain lua interpreter for %s %s",

Reply via email to