the memory could go through the roof with sufficiently high pps, GC now runs at 4x the speed of allocations and doesn’t wait for increase, some callbacks also perform full collection cycle on completion
}
/* Clear the stack, there may be event a/o enything returned */
lua_settop(L, top);
+ lua_gc(L, LUA_GCCOLLECT, 0);
/* Free callback if not recurrent or an error */
if (ret != 0 || uv_timer_get_repeat(timer) == 0) {
uv_close((uv_handle_t *)timer, (uv_close_cb) event_free);
return kr_error(ENOMEM);
}
/* Initialize used libraries. */
+ lua_gc(engine->L, LUA_GCSTOP, 0);
luaL_openlibs(engine->L);
/* Global functions */
lua_pushcfunction(engine->L, l_help);
return ret;
}
+ /* Clean up stack and restart GC */
+ lua_settop(engine->L, 0);
+ lua_gc(engine->L, LUA_GCCOLLECT, 0);
+ lua_gc(engine->L, LUA_GCSETSTEPMUL, 99);
+ lua_gc(engine->L, LUA_GCSETPAUSE, 400);
+ lua_gc(engine->L, LUA_GCRESTART, 0);
return kr_ok();
}
lua_pop(L, 1);
return kr_error(EIO);
}
-
- int n = lua_gettop(L);
- if (n > 0) {
- if (lua_isthread(L, -1)) { /* Continuations */
- status = l_ffi_defer(lua_tothread(L, -1));
- } else if (lua_isnumber(L, -1)) { /* Return code */
- status = lua_tonumber(L, -1);
- }
- lua_pop(L, 1);
+ if (lua_isthread(L, -1)) { /* Continuations */
+ status = l_ffi_defer(lua_tothread(L, -1));
+ } else if (lua_isnumber(L, -1)) { /* Return code */
+ status = lua_tonumber(L, -1);
}
+ lua_pop(L, 1);
return status;
}
*/
#include <uv.h>
+#include <lua.h>
#include <libknot/packet/pkt.h>
#include <libknot/internal/net.h>
#include <contrib/ucw/lib.h>
} else {
mp_delete(mp_context);
}
-#if defined(__GLIBC__) && defined(_GNU_SOURCE)
/* Decommit memory every once in a while */
static int mp_delete_count = 0;
- if (++mp_delete_count == 100 * MP_FREELIST_SIZE) {
+ if (++mp_delete_count == 100000) {
+ lua_gc(worker->engine->L, LUA_GCCOLLECT, 0);
+#if defined(__GLIBC__) && defined(_GNU_SOURCE)
malloc_trim(0);
+#endif
mp_delete_count = 0;
}
-#endif
+
/* Update stats */
worker->stats.concurrent -= 1;
}