Patch session-locking-php.ini-configuration for memcache Bug #63716
Patch version 2012-12-07 11:00 UTC
Return to Bug #63716 |
Download this patch
Patch Revisions:
Developer: marc.neudert@gmail.com
From c28d668c801df2cfabd68e168938360196c55c83 Mon Sep 17 00:00:00 2001
From: Marc Neudert <marc.neudert@gmail.com>
Date: Fri, 7 Dec 2012 11:30:01 +0100
Subject: [PATCH] makes timeout sleep steps configurable through php_ini
---
memcache.c | 38 ++++++++++++++++++++++++++++++++++++++
memcache_pool.h | 2 ++
memcache_session.c | 16 ++++++++++++----
3 files changed, 52 insertions(+), 4 deletions(-)
diff --git a/memcache.c b/memcache.c
index 4fc2795..9969840 100644
--- a/memcache.c
+++ b/memcache.c
@@ -249,6 +249,42 @@ static PHP_INI_MH(OnUpdateLockTimeout) /* {{{ */
}
/* }}} */
+static PHP_INI_MH(OnUpdateLockCheckstepMin) /* {{{ */
+{
+ long int lval;
+
+ lval = strtol(new_value, NULL, 10);
+ if (lval <= 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.lock_checkstep_min must be a positive integer ('%s' given)", new_value);
+ return FAILURE;
+ }
+ if (lval > 1000) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.lock_checkstep_min must be between 1 and 1000 ('%s' given)", new_value);
+ return FAILURE;
+ }
+
+ return OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+}
+/* }}} */
+
+static PHP_INI_MH(OnUpdateLockCheckstepMax) /* {{{ */
+{
+ long int lval;
+
+ lval = strtol(new_value, NULL, 10);
+ if (lval <= 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.lock_checkstep_max must be a positive integer ('%s' given)", new_value);
+ return FAILURE;
+ }
+ if (lval > 1000) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING, "memcache.lock_checkstep_max must be between 1 and 1000 ('%s' given)", new_value);
+ return FAILURE;
+ }
+
+ return OnUpdateLong(entry, new_value, new_value_length, mh_arg1, mh_arg2, mh_arg3, stage TSRMLS_CC);
+}
+/* }}} */
+
/* {{{ PHP_INI */
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("memcache.allow_failover", "1", PHP_INI_ALL, OnUpdateLong, allow_failover, zend_memcache_globals, memcache_globals)
@@ -262,6 +298,8 @@ PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("memcache.session_redundancy", "2", PHP_INI_ALL, OnUpdateRedundancy, session_redundancy, zend_memcache_globals, memcache_globals)
STD_PHP_INI_ENTRY("memcache.compress_threshold", "20000", PHP_INI_ALL, OnUpdateCompressThreshold, compress_threshold, zend_memcache_globals, memcache_globals)
STD_PHP_INI_ENTRY("memcache.lock_timeout", "15", PHP_INI_ALL, OnUpdateLockTimeout, lock_timeout, zend_memcache_globals, memcache_globals)
+ STD_PHP_INI_ENTRY("memcache.lock_checkstep_min", "5", PHP_INI_ALL, OnUpdateLockCheckstepMin, lock_checkstep_min, zend_memcache_globals, memcache_globals)
+ STD_PHP_INI_ENTRY("memcache.lock_checkstep_max", "1000", PHP_INI_ALL, OnUpdateLockCheckstepMax, lock_checkstep_max, zend_memcache_globals, memcache_globals)
PHP_INI_END()
/* }}} */
diff --git a/memcache_pool.h b/memcache_pool.h
index 6440621..13f6624 100644
--- a/memcache_pool.h
+++ b/memcache_pool.h
@@ -403,6 +403,8 @@ ZEND_BEGIN_MODULE_GLOBALS(memcache)
long session_redundancy;
long compress_threshold;
long lock_timeout;
+ long lock_checkstep_min;
+ long lock_checkstep_max;
ZEND_END_MODULE_GLOBALS(memcache)
#ifdef ZTS
diff --git a/memcache_session.c b/memcache_session.c
index 1cd2d29..dd0f04b 100644
--- a/memcache_session.c
+++ b/memcache_session.c
@@ -274,9 +274,17 @@ PS_READ_FUNC(memcache)
mmc_t *mmc;
mmc_request_t *lockrequest, *addrequest, *datarequest;
mmc_queue_t skip_servers = {0};
- unsigned int last_index = 0, prev_index = 0, timeout = 5000;
+ unsigned int last_index = 0, prev_index = 0;
long remainingtime = MEMCACHE_G(lock_timeout) * 1000000 * 2;
+ unsigned int timeout_min = MEMCACHE_G(lock_checkstep_min) * 1000;
+ unsigned int timeout_max = MEMCACHE_G(lock_checkstep_max) * 1000;
+ unsigned int timeout = timeout_min;
+
+ if (timeout_max < timeout_min) {
+ timeout_max = timeout_min;
+ }
+
lockparam[0] = &lockresult;
lockparam[1] = NULL;
lockparam[2] = NULL;
@@ -342,9 +350,9 @@ PS_READ_FUNC(memcache)
remainingtime -= timeout;
timeout *= 2;
- /* max value to usleep() is 1 second */
- if (timeout > 1000000) {
- timeout = 1000000;
+ /* max value to usleep() is 1 second (also limit of timeout_max) */
+ if (timeout > timeout_max) {
+ timeout = timeout_max;
}
}
} while (skip_servers.len < MEMCACHE_G(session_redundancy)-1 && skip_servers.len < pool->num_servers && remainingtime > 0);
--
1.7.7.6
|