]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
OPTIM/MEDIUM: lua: executes the garbage collector only when using cosocket
authorThierry FOURNIER <tfournier@arpalert.org>
Sun, 27 Sep 2015 20:53:33 +0000 (22:53 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 27 Sep 2015 20:56:40 +0000 (22:56 +0200)
The garbage collector is a little bit heavy to run, and it was added
only for cosockets. This patch prevent useless executions when no
cosockets are used.

include/types/hlua.h
src/hlua.c

index 43916d482e1e297929d22bb54ccd788e962c3016..1bf2a753937acad3d6a46bcb27261d6f6b602fa0 100644 (file)
@@ -25,6 +25,7 @@ struct stream;
 #define HLUA_WAKERESWR 0x00000004
 #define HLUA_WAKEREQWR 0x00000008
 #define HLUA_EXIT      0x00000010
+#define HLUA_MUST_GC   0x00000020
 
 enum hlua_exec {
        HLUA_E_OK = 0,
index b893a47b6595e540f2c20006de5c9782f041cc2b..d205a38798cbf1487c336283ad8e1e802bec22b7 100644 (file)
@@ -923,9 +923,11 @@ void hlua_ctx_destroy(struct hlua *lua)
         * NOTE: maybe this action locks all the Lua threads untiml the en of
         * the garbage collection.
         */
-       lua_gc(lua->T, LUA_GCCOLLECT, 0);
-       if (lua_status(lua->T) != LUA_OK)
-               lua_gc(gL.T, LUA_GCCOLLECT, 0);
+       if (lua->flags & HLUA_MUST_GC) {
+               lua_gc(lua->T, LUA_GCCOLLECT, 0);
+               if (lua_status(lua->T) != LUA_OK)
+                       lua_gc(gL.T, LUA_GCCOLLECT, 0);
+       }
 
        lua->T = NULL;
 }
@@ -1166,7 +1168,8 @@ timeout_reached:
        }
 
        /* This GC permits to destroy some object when a Lua timeout strikes. */
-       if (ret != HLUA_E_AGAIN)
+       if (lua->flags & HLUA_MUST_GC &&
+           ret != HLUA_E_AGAIN)
                lua_gc(lua->T, LUA_GCCOLLECT, 0);
 
        switch (ret) {
@@ -2253,6 +2256,8 @@ __LJMP static int hlua_socket_connect(struct lua_State *L)
        si_applet_cant_put(&socket->s->si[0]);
        appctx_wakeup(appctx);
 
+       hlua->flags |= HLUA_MUST_GC;
+
        if (!hlua_com_new(hlua, &appctx->ctx.hlua.wake_on_write))
                WILL_LJMP(luaL_error(L, "out of memory"));
        WILL_LJMP(hlua_yieldk(L, 0, 0, hlua_socket_connect_yield, TICK_ETERNITY, 0));