X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fms_task.c;h=f2cb8657d678bc2088aea873155fc6962cdd404a;hb=88b1aa19c0b3c5ad047222618cb17f447ea2bc67;hp=bcd2757c0b0453d6a944b0d59344751a7aa35a5c;hpb=d39962cd481eb10a7d9dceb6d442af0fd49521fb;p=awesomized%2Flibmemcached diff --git a/clients/ms_task.c b/clients/ms_task.c index bcd2757c..f2cb8657 100644 --- a/clients/ms_task.c +++ b/clients/ms_task.c @@ -9,9 +9,15 @@ * */ -#include "config.h" +#include "mem_config.h" -#include +#if defined(HAVE_SYS_TIME_H) +# include +#endif + +#if defined(HAVE_TIME_H) +# include +#endif #include "ms_thread.h" #include "ms_setting.h" @@ -30,7 +36,7 @@ static ms_task_item_t *ms_get_cur_opt_item(ms_conn_t *c); static ms_task_item_t *ms_get_next_get_item(ms_conn_t *c); static ms_task_item_t *ms_get_next_set_item(ms_conn_t *c); -static ms_task_item_t *ms_get_pre_set_item(ms_conn_t *c); +static ms_task_item_t *ms_get_random_overwrite_item(ms_conn_t *c); /* select next operation to do */ @@ -44,7 +50,7 @@ static void ms_kick_out_item(ms_task_item_t *item); /* miss rate adjustment */ -static bool ms_need_overwirte_item(ms_task_t *task); +static bool ms_need_overwrite_item(ms_task_t *task); static bool ms_adjust_opt(ms_conn_t *c, ms_task_t *task); @@ -144,18 +150,10 @@ static ms_task_item_t *ms_get_next_set_item(ms_conn_t *c) * @return ms_task_item_t*, the pointer of the previous item of * set operation */ -static ms_task_item_t *ms_get_pre_set_item(ms_conn_t *c) +static ms_task_item_t *ms_get_random_overwrite_item(ms_conn_t *c) { - if (c->set_cursor <= 0) - { - return &c->item_win[0]; - } - else - { - return &c->item_win[(int64_t)-- c->set_cursor % c->win_size]; - } -} /* ms_get_pre_set_item */ - + return ms_get_next_get_item(c); +} /* ms_get_random_overwrite_item */ /** * According to the proportion of operations(get or set), select @@ -291,7 +289,7 @@ static void ms_kick_out_item(ms_task_item_t *item) * @return bool, if need overwrite, return true, else return * false */ -static bool ms_need_overwirte_item(ms_task_t *task) +static bool ms_need_overwrite_item(ms_task_t *task) { ms_task_item_t *item= task->item; @@ -345,7 +343,7 @@ static bool ms_adjust_opt(ms_conn_t *c, ms_task_t *task) /* If the current item is not a new item, kick it out */ if (item->value_offset != INVALID_OFFSET) { - if (ms_need_overwirte_item(task)) + if (ms_need_overwrite_item(task)) { /* overwrite */ task->overwrite_set++; @@ -359,17 +357,23 @@ static bool ms_adjust_opt(ms_conn_t *c, ms_task_t *task) else /* it's a new item */ { /* need overwrite */ - if (ms_need_overwirte_item(task)) + if (ms_need_overwrite_item(task)) { - item= ms_get_pre_set_item(c); + /** + * overwrite not use the item with current set cursor, revert + * set cursor. + */ + c->set_cursor--; + + item= ms_get_random_overwrite_item(c); if (item->value_offset != INVALID_OFFSET) { task->item= item; task->overwrite_set++; } - else /* previous set item is a new item */ + else /* item is a new item */ { - /* select the previous item to run, and cancel overwrite */ + /* select the item to run, and cancel overwrite */ task->item= item; } } @@ -591,7 +595,7 @@ static void ms_warmup_server(ms_conn_t *c) */ if (c->remain_warmup_num == -1) { - ms_send_signal(&ms_global.init_lock); + ms_send_signal(&ms_global.warmup_lock); c->remain_warmup_num--; /* never run the if branch */ } } /* ms_warmup_server */ @@ -619,7 +623,7 @@ static void ms_single_getset_task_sch(ms_conn_t *c) else if (task->cmd == CMD_GET) { assert(task->cmd == CMD_GET); - ms_mcd_get(c, item, task->verify); + ms_mcd_get(c, item); } } } /* ms_single_getset_task_sch */ @@ -1045,7 +1049,7 @@ static void ms_update_task_result(ms_conn_t *c) * * @param c, pointer of the concurrency * - * @return int, if success, return 0, else return -1 + * @return int, if success, return EXIT_SUCCESS, else return -1 */ static int ms_run_getset_task(ms_conn_t *c) { @@ -1077,7 +1081,7 @@ static int ms_run_getset_task(ms_conn_t *c) return -1; } - return 0; + return EXIT_SUCCESS; } /* ms_run_getset_task */ @@ -1086,7 +1090,7 @@ static int ms_run_getset_task(ms_conn_t *c) * * @param c, pointer of the concurrency * - * @return int, if success, return 0, else return -1 + * @return int, if success, return EXIT_SUCCESS, else return -1 */ int ms_exec_task(struct conn *c) { @@ -1102,5 +1106,5 @@ int ms_exec_task(struct conn *c) } } - return 0; + return EXIT_SUCCESS; } /* ms_exec_task */