travis: install python-sphinx
[m6w6/libmemcached] / clients / ms_thread.h
1 /*
2 * File: ms_thread.h
3 * Author: Mingqiang Zhuang
4 *
5 * Created on February 10, 2009
6 *
7 * (c) Copyright 2009, Schooner Information Technology, Inc.
8 * http://www.schoonerinfotech.com/
9 *
10 */
11
12 /**
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
25 * thread.
26 */
27 #ifndef MS_THREAD_H
28 #define MS_THREAD_H
29
30 #include <sched.h>
31 #include "ms_conn.h"
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /** Time relative to server start. Smaller than time_t on 64-bit systems. */
38 typedef unsigned int rel_time_t;
39
40 /* Used to store the context of each thread */
41 typedef struct thread_ctx
42 {
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 */
48 } ms_thread_ctx_t;
49
50 /* Used to store the private variables of each thread */
51 typedef struct thread
52 {
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 */
55
56 ms_thread_ctx_t *thread_ctx; /* thread context from the caller */
57 struct event_base *base; /* libevent handler created by this thread */
58
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 */
62
63 struct timeval startup_time; /* start time of the thread */
64 } ms_thread_t;
65
66 /* initialize threads */
67 void ms_thread_init(void);
68
69
70 /* cleanup some resource of threads when all the threads exit */
71 void ms_thread_cleanup(void);
72
73
74 #ifdef __cplusplus
75 }
76 #endif
77
78 #endif /* end of MS_THREAD_H */