]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: lua: Lua initialisation "on demand"
authorThierry FOURNIER <tfournier@exceliance.fr>
Fri, 27 Feb 2015 17:37:27 +0000 (18:37 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Feb 2015 22:12:37 +0000 (23:12 +0100)
Actually, the Lua context is always initilized in each
session, even if the session doesn't use Lua. This
behavior cause 5% performances loss.

This patch initilize the Lua only if it is use by the
session. The initialization is now on demand.

src/hlua.c
src/session.c

index de27ba25abe2b40fb2a33f61e2a66dac2edb8a3c..a0e4d91b49663fb357c2a73781ce3ebe8f351392 100644 (file)
@@ -2709,6 +2709,18 @@ static int hlua_sample_conv_wrapper(struct session *session, const struct arg *a
 {
        struct hlua_function *fcn = (struct hlua_function *)private;
 
+       /* In the execution wrappers linked with a session, the
+        * Lua context can be not initialized. This behavior
+        * permits to save performances because a systematic
+        * Lua initialization cause 5% performances loss.
+        */
+       if (!session->hlua.T && !hlua_ctx_init(&session->hlua, session->task)) {
+               send_log(session->be, LOG_ERR, "Lua converter '%s': can't initialize Lua context.", fcn->name);
+               if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
+                       Alert("Lua converter '%s': can't initialize Lua context.\n", fcn->name);
+               return 0;
+       }
+
        /* If it is the first run, initialize the data for the call. */
        if (session->hlua.state == HLUA_STOP) {
                /* Check stack available size. */
@@ -2796,6 +2808,18 @@ static int hlua_sample_fetch_wrapper(struct proxy *px, struct session *s, void *
 {
        struct hlua_function *fcn = (struct hlua_function *)private;
 
+       /* In the execution wrappers linked with a session, the
+        * Lua context can be not initialized. This behavior
+        * permits to save performances because a systematic
+        * Lua initialization cause 5% performances loss.
+        */
+       if (!s->hlua.T && !hlua_ctx_init(&s->hlua, s->task)) {
+               send_log(s->be, LOG_ERR, "Lua sample-fetch '%s': can't initialize Lua context.", fcn->name);
+               if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
+                       Alert("Lua sample-fetch '%s': can't initialize Lua context.\n", fcn->name);
+               return 0;
+       }
+
        /* If it is the first run, initialize the data for the call. */
        if (s->hlua.state == HLUA_STOP) {
                /* Check stack available size. */
@@ -3063,6 +3087,18 @@ static int hlua_request_act_wrapper(struct hlua_rule *rule, struct proxy *px,
 {
        char **arg;
 
+       /* In the execution wrappers linked with a session, the
+        * Lua context can be not initialized. This behavior
+        * permits to save performances because a systematic
+        * Lua initialization cause 5% performances loss.
+        */
+       if (!s->hlua.T && !hlua_ctx_init(&s->hlua, s->task)) {
+               send_log(px, LOG_ERR, "Lua action '%s': can't initialize Lua context.", rule->fcn.name);
+               if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE))
+                       Alert("Lua action '%s': can't initialize Lua context.\n", rule->fcn.name);
+               return 0;
+       }
+
        /* If it is the first run, initialize the data for the call. */
        if (s->hlua.state == HLUA_STOP) {
                /* Check stack available size. */
index 7ab91e6b6bb6e72b790139c8c97d4e2c85ed4b9d..77ec4ca2ab761f52e4c807e4db28b8de0d21ddc3 100644 (file)
@@ -545,8 +545,7 @@ int session_complete(struct session *s)
        txn->rsp.chn = s->rep;
 
 #ifdef USE_LUA
-       if (!hlua_ctx_init(&s->hlua, s->task))
-               goto out_free_rep;
+       s->hlua.T = NULL;
 #endif
 
        /* finish initialization of the accepted file descriptor */
@@ -557,7 +556,7 @@ int session_complete(struct session *s)
                 * finished (=0, eg: monitoring), in both situations,
                 * we can release everything and close.
                 */
-               goto out_free_lua;
+               goto out_free_rep;
        }
 
        /* if logs require transport layer information, note it on the connection */
@@ -575,11 +574,6 @@ int session_complete(struct session *s)
        return 1;
 
        /* Error unrolling */
- out_free_lua:
-#ifdef USE_LUA
-       hlua_ctx_destroy(&s->hlua);
-#endif
-
  out_free_rep:
        pool_free2(pool2_channel, s->rep);
  out_free_req:
@@ -642,7 +636,8 @@ static void session_free(struct session *s)
                session_offer_buffers();
 
 #ifdef USE_LUA
-       hlua_ctx_destroy(&s->hlua);
+       if (s->hlua.T)
+               hlua_ctx_destroy(&s->hlua);
 #endif
 
        pool_free2(pool2_channel, s->req);