Skip to content

Commit 3ae7350

Browse files
RedisArray performance experimentation
Experiment with persistent connections and Unix Sockets in the context of RedisArray.
1 parent 89bdaf2 commit 3ae7350

File tree

4 files changed

+26
-8
lines changed

4 files changed

+26
-8
lines changed

redis_array.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ PHP_METHOD(RedisArray, __construct)
190190
char *name = NULL;
191191
int id;
192192
RedisArray *ra = NULL;
193-
zend_bool b_index = 0, b_autorehash = 0;
193+
zend_bool b_index = 0, b_autorehash = 0, b_pconnect = 0;
194194
HashTable *hPrev = NULL, *hOpts = NULL;
195195

196196
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|a", &z0, &z_opts) == FAILURE) {
@@ -232,6 +232,11 @@ PHP_METHOD(RedisArray, __construct)
232232
if(FAILURE != zend_hash_find(hOpts, "autorehash", sizeof("autorehash"), (void**)&zpData) && Z_TYPE_PP(zpData) == IS_BOOL) {
233233
b_autorehash = Z_BVAL_PP(zpData);
234234
}
235+
236+
/* extract pconnect option. */
237+
if(FAILURE != zend_hash_find(hOpts, "pconnect", sizeof("pconnect"), (void**)&zpData) && Z_TYPE_PP(zpData) == IS_BOOL) {
238+
b_pconnect = Z_BVAL_PP(zpData);
239+
}
235240
}
236241

237242
/* extract either name of list of hosts from z0 */
@@ -241,7 +246,7 @@ PHP_METHOD(RedisArray, __construct)
241246
break;
242247

243248
case IS_ARRAY:
244-
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_dist, hPrev, b_index TSRMLS_CC);
249+
ra = ra_make_array(Z_ARRVAL_P(z0), z_fun, z_dist, hPrev, b_index, b_pconnect TSRMLS_CC);
245250
break;
246251

247252
default:

redis_array.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ typedef struct RedisArray_ {
3737
zval *z_multi_exec; /* Redis instance to be used in multi-exec */
3838
zend_bool index; /* use per-node index */
3939
zend_bool auto_rehash; /* migrate keys on read operations */
40+
zend_bool pconnect; /* should we use persistant connections */
4041
zval *z_fun; /* key extractor, callable */
4142
zval *z_dist; /* key distributor, callable */
4243
zval *z_pure_cmds; /* hash table */

redis_array_impl.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ ra_load_hosts(RedisArray *ra, HashTable *hosts TSRMLS_DC)
6767
call_user_function(&redis_ce->function_table, &ra->redis[i], &z_cons, &z_ret, 0, NULL TSRMLS_CC);
6868

6969
/* create socket */
70-
redis_sock = redis_sock_create(host, host_len, port, 0, 0, NULL); /* TODO: persistence? */
70+
redis_sock = redis_sock_create(host, host_len, port, 0, ra->pconnect, NULL); /* TODO: persistence? */
7171

7272
/* connect */
7373
redis_sock_server_open(redis_sock, 1 TSRMLS_CC);
@@ -157,9 +157,10 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
157157
zval *z_params_funs, **z_data_pp, *z_fun = NULL, *z_dist = NULL;
158158
zval *z_params_index;
159159
zval *z_params_autorehash;
160+
zval *z_params_pconnect;
160161
RedisArray *ra = NULL;
161162

162-
zend_bool b_index = 0, b_autorehash = 0;
163+
zend_bool b_index = 0, b_autorehash = 0, b_pconnect;
163164
HashTable *hHosts = NULL, *hPrev = NULL;
164165

165166
/* find entry */
@@ -222,8 +223,18 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
222223
}
223224
}
224225

226+
/* pconnect option */
227+
MAKE_STD_ZVAL(z_params_pconnect);
228+
array_init(z_params_pconnect);
229+
sapi_module.treat_data(PARSE_STRING, estrdup(INI_STR("redis.arrays.pconnect")), z_params_pconnect TSRMLS_CC);
230+
if (zend_hash_find(Z_ARRVAL_P(z_params_pconnect), name, strlen(name) + 1, (void**) &z_data_pp) != FAILURE) {
231+
if(Z_TYPE_PP(z_data_pp) == IS_STRING && strncmp(Z_STRVAL_PP(z_data_pp), "1", 1) == 0) {
232+
b_pconnect = 1;
233+
}
234+
}
235+
225236
/* create RedisArray object */
226-
ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index TSRMLS_CC);
237+
ra = ra_make_array(hHosts, z_fun, z_dist, hPrev, b_index, b_pconnect TSRMLS_CC);
227238
ra->auto_rehash = b_autorehash;
228239

229240
/* cleanup */
@@ -242,7 +253,7 @@ RedisArray *ra_load_array(const char *name TSRMLS_DC) {
242253
}
243254

244255
RedisArray *
245-
ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index TSRMLS_DC) {
256+
ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, zend_bool b_pconnect TSRMLS_DC) {
246257

247258
int count = zend_hash_num_elements(hosts);
248259

@@ -256,14 +267,15 @@ ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev
256267
ra->z_multi_exec = NULL;
257268
ra->index = b_index;
258269
ra->auto_rehash = 0;
270+
ra->pconnect = b_pconnect;
259271

260272
/* init array data structures */
261273
ra_init_function_table(ra);
262274

263275
if(NULL == ra_load_hosts(ra, hosts TSRMLS_CC)) {
264276
return NULL;
265277
}
266-
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index TSRMLS_CC) : NULL;
278+
ra->prev = hosts_prev ? ra_make_array(hosts_prev, z_fun, z_dist, NULL, b_index, b_pconnect TSRMLS_CC) : NULL;
267279

268280
/* copy function if provided */
269281
if(z_fun) {

redis_array_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
RedisArray* ra_load_hosts(RedisArray *ra, HashTable *hosts TSRMLS_DC);
99
RedisArray *ra_load_array(const char *name TSRMLS_DC);
10-
RedisArray *ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index TSRMLS_DC);
10+
RedisArray *ra_make_array(HashTable *hosts, zval *z_fun, zval *z_dist, HashTable *hosts_prev, zend_bool b_index, zend_bool b_pconnect TSRMLS_DC);
1111
zval *ra_find_node_by_name(RedisArray *ra, const char *host, int host_len TSRMLS_DC);
1212
zval *ra_find_node(RedisArray *ra, const char *key, int key_len, int *out_pos TSRMLS_DC);
1313
void ra_init_function_table(RedisArray *ra);

0 commit comments

Comments
 (0)