Commit 471ad43c authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Speedup toku_hashtable_random_pick

git-svn-id: file:///svn/tokudb@134 c7de825b-a66e-492c-adef-691d508d4ae1
parent 8242d2e0
...@@ -709,9 +709,10 @@ static int push_some_kvpairs_down (BRT t, BRTNODE node, int childnum, ...@@ -709,9 +709,10 @@ static int push_some_kvpairs_down (BRT t, BRTNODE node, int childnum,
{ {
bytevec key,val; bytevec key,val;
ITEMLEN keylen, vallen; ITEMLEN keylen, vallen;
long int randomnumber = random();
//printf("%s:%d Try random_pick, weight=%d \n", __FILE__, __LINE__, node->u.n.n_bytes_in_hashtable[childnum]); //printf("%s:%d Try random_pick, weight=%d \n", __FILE__, __LINE__, node->u.n.n_bytes_in_hashtable[childnum]);
assert(toku_hashtable_n_entries(node->u.n.htables[childnum])>0); assert(toku_hashtable_n_entries(node->u.n.htables[childnum])>0);
while(0==toku_hashtable_random_pick(node->u.n.htables[childnum], &key, &keylen, &val, &vallen)) { while(0==toku_hashtable_random_pick(node->u.n.htables[childnum], &key, &keylen, &val, &vallen, &randomnumber)) {
int child_did_split=0; BRTNODE childa, childb; int child_did_split=0; BRTNODE childa, childb;
DBT hk,hv; DBT hk,hv;
DBT childsplitk; DBT childsplitk;
......
...@@ -134,9 +134,9 @@ int toku_hash_delete (HASHTABLE tab, const void *key, ITEMLEN keylen) { ...@@ -134,9 +134,9 @@ int toku_hash_delete (HASHTABLE tab, const void *key, ITEMLEN keylen) {
} }
int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen) { int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen, long int *randomnumber) {
unsigned int i; unsigned int i;
unsigned int usei = random()%h->arraysize; unsigned int usei = (*randomnumber)%h->arraysize;
for (i=0; i<h->arraysize; i++, usei++) { for (i=0; i<h->arraysize; i++, usei++) {
if (usei>=h->arraysize) usei=0; if (usei>=h->arraysize) usei=0;
HASHELT he=h->array[usei]; HASHELT he=h->array[usei];
...@@ -145,6 +145,7 @@ int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytev ...@@ -145,6 +145,7 @@ int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytev
*keylen = he->keylen; *keylen = he->keylen;
*data = &he->keyval[he->keylen]; *data = &he->keyval[he->keylen];
*datalen = he->vallen; *datalen = he->vallen;
*randomnumber = usei;
return 0; return 0;
} }
} }
......
...@@ -24,7 +24,7 @@ int toku_hashtable_n_entries(HASHTABLE); ...@@ -24,7 +24,7 @@ int toku_hashtable_n_entries(HASHTABLE);
void toku_hashtable_clear(HASHTABLE); void toku_hashtable_clear(HASHTABLE);
int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen); int toku_hashtable_random_pick(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen, long int *randomnumber);
//int hashtable_find_last(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen); //int hashtable_find_last(HASHTABLE h, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
typedef struct hashelt *HASHELT; typedef struct hashelt *HASHELT;
......
...@@ -127,7 +127,8 @@ void test1(void) { ...@@ -127,7 +127,8 @@ void test1(void) {
for (j=0; j<4; j++) { for (j=0; j<4; j++) {
bytevec key, val; bytevec key, val;
ITEMLEN keylen, vallen; ITEMLEN keylen, vallen;
r = toku_hashtable_random_pick(table, &key, &keylen, &val, &vallen); long int randnum=random();
r = toku_hashtable_random_pick(table, &key, &keylen, &val, &vallen, &randnum);
assert(r==0); assert(r==0);
r = toku_hash_delete(table, key, keylen); r = toku_hash_delete(table, key, keylen);
assert(r==0); assert(r==0);
......
...@@ -62,7 +62,7 @@ int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) { ...@@ -62,7 +62,7 @@ int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
return key1len-key2len; return key1len-key2len;
} }
#else #else
/* unroll that one twice */ /* unroll that one four times */
int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) { int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len) {
int comparelen = key1len<key2len ? key1len : key2len; int comparelen = key1len<key2len ? key1len : key2len;
const unsigned char *k1; const unsigned char *k1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment