3 * Author: Mingqiang Zhuang
5 * Created on February 10, 2009
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
13 * Asynchronous memslap has the similar implementation of
14 * multi-threads with memcached. Asynchronous memslap creates
15 * one or more self-governed threads; each thread is bound with
16 * one CPU core if the system supports setting CPU core
17 * affinity. And every thread has private variables. There is
18 * less communication or some shared resources among all the
19 * threads. It can improve the performance because there are
20 * fewer locks and competition. In addition, each thread has a
21 * libevent to manage the events of network. Each thread has one
22 * or more self-governed concurrencies; each concurrency has one
23 * or more socket connections. All the concurrencies don't
24 * communicate with each other even though they are in the same
37 /** Time relative to server start. Smaller than time_t on 64-bit systems. */
38 typedef unsigned int rel_time_t
;
40 /* Used to store the context of each thread */
41 typedef struct thread_ctx
43 uint32_t thd_idx
; /* the thread index */
44 uint32_t nconns
; /* how many connections included by the thread */
45 uint32_t srv_idx
; /* index of the thread */
46 int tps_perconn
; /* expected throughput per connection */
47 int64_t exec_num_perconn
; /* execute number per connection */
50 /* Used to store the private variables of each thread */
53 ms_conn_t
*conn
; /* conn array to store all the conn in the thread */
54 uint32_t nactive_conn
; /* how many connects are active */
56 ms_thread_ctx_t
*thread_ctx
; /* thread context from the caller */
57 struct event_base
*base
; /* libevent handler created by this thread */
59 rel_time_t curr_time
; /* current time */
60 struct event clock_event
; /* clock event to time each one second */
61 bool initialized
; /* whether clock_event has been initialized */
63 struct timeval startup_time
; /* start time of the thread */
66 /* initialize threads */
67 void ms_thread_init(void);
70 /* cleanup some resource of threads when all the threads exit */
71 void ms_thread_cleanup(void);
78 #endif /* end of MS_THREAD_H */