Skip to content

Revert to old retry algorithm #355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
memcached extension changelog

Version 4.0.0 (????-??-??)

* Remove exponential backoff in retry and revert to old behavior (#355)

Version 3.0.3 (2017-02-19)
--------------------------

Expand Down
20 changes: 7 additions & 13 deletions memcached.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@
; the default is On
;memcached.sess_locking = On

; The minimum time, in milliseconds, to wait between session lock attempts.
; This value is double on each lock retry until memcached.sess_lock_wait_max
; is reached, after which any further retries will take sess_lock_wait_max seconds.
; Default is 1000.
;memcached.sess_lock_wait_min = 1000;

; The maximum time, in milliseconds, to wait between session lock attempts.
; Default is 2000.
;memcached.sess_lock_wait_max = 2000;

; The number of times to retry locking the session lock, not including the first attempt.
; Default is 5.
;memcached.sess_lock_retries = 5;
; The time, in milliseconds, to wait between session lock attempts.
; Default is 150.
;memcached.sess_lock_wait = 150;

; The number of times to retry locking the session lock.
; Default is -1, which means to retry for max_execution_time of the script.
;memcached.sess_lock_retries = -1;

; The time, in seconds, before a lock should release itself.
; Setting to 0 results in the default behaviour, which is to
Expand Down
24 changes: 4 additions & 20 deletions php_memcached.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,6 @@ static PHP_INI_MH(OnUpdateSerializer)
return OnUpdateString(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
}

static
PHP_INI_MH(OnUpdateDeprecatedLockValue)
{
if (ZSTR_LEN(new_value) > 0 && strcmp(ZSTR_VAL(new_value), "not set")) {
php_error_docref(NULL, E_DEPRECATED, "memcached.sess_lock_wait and memcached.sess_lock_max_wait are deprecated. Please update your configuration to use memcached.sess_lock_wait_min, memcached.sess_lock_wait_max and memcached.sess_lock_retries");
}
return FAILURE;
}

static
PHP_INI_MH(OnUpdateSessionPrefixString)
{
Expand Down Expand Up @@ -329,9 +320,8 @@ PHP_INI_BEGIN()

#ifdef HAVE_MEMCACHED_SESSION
MEMC_SESSION_INI_ENTRY("locking", "1", OnUpdateBool, lock_enabled)
MEMC_SESSION_INI_ENTRY("lock_wait_min", "1000", OnUpdateLongGEZero, lock_wait_min)
MEMC_SESSION_INI_ENTRY("lock_wait_max", "2000", OnUpdateLongGEZero, lock_wait_max)
MEMC_SESSION_INI_ENTRY("lock_retries", "5", OnUpdateLong, lock_retries)
MEMC_SESSION_INI_ENTRY("lock_wait", "150", OnUpdateLongGEZero, lock_wait)
MEMC_SESSION_INI_ENTRY("lock_retries", "-1", OnUpdateLong, lock_retries)
MEMC_SESSION_INI_ENTRY("lock_expire", "0", OnUpdateLongGEZero, lock_expiration)
#if defined(LIBMEMCACHED_VERSION_HEX) && LIBMEMCACHED_VERSION_HEX < 0x01000018
MEMC_SESSION_INI_ENTRY("binary_protocol", "0", OnUpdateBool, binary_protocol_enabled)
Expand All @@ -348,11 +338,6 @@ PHP_INI_BEGIN()
MEMC_SESSION_INI_ENTRY("sasl_password", "", OnUpdateString, sasl_password)
MEMC_SESSION_INI_ENTRY("prefix", "memc.sess.", OnUpdateSessionPrefixString, prefix)
MEMC_SESSION_INI_ENTRY("persistent", "0", OnUpdateBool, persistent_enabled)

/* Deprecated */
STD_PHP_INI_ENTRY("memcached.sess_lock_wait", "not set", PHP_INI_ALL, OnUpdateDeprecatedLockValue, no_effect, zend_php_memcached_globals, php_memcached_globals)
STD_PHP_INI_ENTRY("memcached.sess_lock_max_wait", "not set", PHP_INI_ALL, OnUpdateDeprecatedLockValue, no_effect, zend_php_memcached_globals, php_memcached_globals)

#endif

MEMC_INI_ENTRY("compression_type", "fastlz", OnUpdateCompressionType, compression_name)
Expand Down Expand Up @@ -4069,9 +4054,8 @@ PHP_GINIT_FUNCTION(php_memcached)
#ifdef HAVE_MEMCACHED_SESSION

php_memcached_globals->session.lock_enabled = 0;
php_memcached_globals->session.lock_wait_max = 2000;
php_memcached_globals->session.lock_wait_min = 1000;
php_memcached_globals->session.lock_retries = 5;
php_memcached_globals->session.lock_wait = 150;
php_memcached_globals->session.lock_retries = -1;
php_memcached_globals->session.lock_expiration = 30;
php_memcached_globals->session.binary_protocol_enabled = 1;
php_memcached_globals->session.consistent_hash_enabled = 1;
Expand Down
3 changes: 1 addition & 2 deletions php_memcached_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ ZEND_BEGIN_MODULE_GLOBALS(php_memcached)
/* Session related variables */
struct {
zend_bool lock_enabled;
zend_long lock_wait_max;
zend_long lock_wait_min;
zend_long lock_wait;
zend_long lock_retries;
zend_long lock_expiration;

Expand Down
15 changes: 5 additions & 10 deletions php_memcached_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,6 @@ typedef struct {
zend_string *lock_key;
} php_memcached_user_data;

#ifndef MIN
# define MIN(a,b) (((a)<(b))?(a):(b))
#endif

#ifndef MAX
# define MAX(a,b) (((a)>(b))?(a):(b))
#endif

#ifdef ZTS
#define MEMC_SESS_INI(v) TSRMG(php_memcached_globals_id, zend_php_memcached_globals *, session.v)
#else
Expand Down Expand Up @@ -143,9 +135,13 @@ zend_bool s_lock_session(memcached_st *memc, zend_string *sid)
lock_key_len = spprintf(&lock_key, 0, "lock.%s", sid->val);
expiration = s_lock_expiration();

wait_time = MEMC_SESS_INI(lock_wait_min);
wait_time = MEMC_SESS_INI(lock_wait);
retries = MEMC_SESS_INI(lock_retries);

if (retries < 0) {
retries = zend_ini_long(ZEND_STRS("max_execution_time"), 0) / 1000 * wait_time;
}

do {
rc = memcached_add(memc, lock_key, lock_key_len, "1", sizeof ("1") - 1, expiration, 0);

Expand All @@ -160,7 +156,6 @@ zend_bool s_lock_session(memcached_st *memc, zend_string *sid)
case MEMCACHED_DATA_EXISTS:
if (retries > 0) {
usleep(wait_time * 1000);
wait_time = MIN(MEMC_SESS_INI(lock_wait_max), wait_time * 2);
}
break;

Expand Down
5 changes: 2 additions & 3 deletions tests/session_lock-php71.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ if (PHP_VERSION_ID < 70100) print "skip";
?>
--INI--
memcached.sess_locking = true
memcached.sess_lock_wait_min = 500
memcached.sess_lock_wait_max = 1000
memcached.sess_lock_wait = 500
memcached.sess_lock_retries = 3
memcached.sess_prefix = "memc.test."

Expand Down Expand Up @@ -50,7 +49,7 @@ $time_start = microtime(true);
session_start();
$time = microtime(true) - $time_start;

if (round ($time, 1) != 2.5) {
if (round ($time, 1) != 1.5) {
echo "Waited longer than expected: $time" . PHP_EOL;
}
echo "OK";
Expand Down