2
0
Fork 0

[core] Change behaviour of connection garbage collector in worker a bit, only free if below threshold for more than 5 minutes

This commit is contained in:
Thomas Porzelt 2009-11-07 13:21:46 +01:00
parent 53096333f1
commit 175db515a6
1 changed files with 14 additions and 10 deletions

View File

@ -670,18 +670,22 @@ void li_worker_con_put(liConnection *con) {
li_connection_reset(con);
/* realloc wrk->connections if it makes sense (too many allocated, only every 60sec) */
/* if (active < allocated*0.70) { allocated *= 0.85 } */
/* free unused connections if it makes sense (more than 30% unused, if longer than 5min, free 15%) */
threshold = (wrk->connections->len * 7) / 10;
if (wrk->connections_active < threshold && (now - wrk->connections_gc_ts) > 60.0 && wrk->connections->len > 10) {
/* realloc */
guint i;
threshold = (wrk->connections->len * 85) / 100;
for (i = wrk->connections->len; i > threshold; i--) {
li_connection_free(g_array_index(wrk->connections, liConnection*, i-1));
g_array_index(wrk->connections, liConnection*, i-1) = NULL;
if (wrk->connections_active < threshold && wrk->connections->len > 10) {
/* below treshold but for how long? */
if ((now - wrk->connections_gc_ts) > 300.0) {
/* free unused cons */
guint i;
threshold = (wrk->connections->len * 85) / 100;
for (i = wrk->connections->len; i > threshold; i--) {
li_connection_free(g_array_index(wrk->connections, liConnection*, i-1));
g_array_index(wrk->connections, liConnection*, i-1) = NULL;
}
wrk->connections->len = threshold;
}
wrk->connections->len = threshold;
} else {
/* above treshold, update timestamp */
wrk->connections_gc_ts = now;
}
}