X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=clients%2Fms_task.c;h=7e7921fcf2b9b6cc44e17c84bfd39e1b5461c20f;hb=0302d893ad986b16a186b8b145c08e8599e3804a;hp=bcd2757c0b0453d6a944b0d59344751a7aa35a5c;hpb=c67da677fe0944d3d2d3ff46e65fc3bc775404ae;p=m6w6%2Flibmemcached diff --git a/clients/ms_task.c b/clients/ms_task.c index bcd2757c..7e7921fc 100644 --- a/clients/ms_task.c +++ b/clients/ms_task.c @@ -12,6 +12,16 @@ #include "config.h" #include +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif #include "ms_thread.h" #include "ms_setting.h" @@ -30,7 +40,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 +54,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 +154,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 +293,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 +347,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 +361,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 +599,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 +627,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 +1053,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 +1085,7 @@ static int ms_run_getset_task(ms_conn_t *c) return -1; } - return 0; + return EXIT_SUCCESS; } /* ms_run_getset_task */ @@ -1086,7 +1094,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 +1110,5 @@ int ms_exec_task(struct conn *c) } } - return 0; + return EXIT_SUCCESS; } /* ms_exec_task */