Skip to content

Commit e4c7bd4

Browse files
committed
Dedicated queue writers
Increasing the number of writers on the master does not always improve database performance. More often than not it increases contention and hurts performance. But queues may be an exception: only one client can consume from a queue at a time, that it could make sense for queue consumers to run in parellel as much as possible. On a tunable, this patch dispatches queue consumes to dedicated writer threads. The handle_buf code is also refactored to use thdpool. Signed-off-by: Rivers Zhang <[email protected]>
1 parent e118ae1 commit e4c7bd4

18 files changed

+523
-883
lines changed

Diff for: bbinc/thdpool.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ typedef void (*thdpool_thddque_fn)(struct thdpool *pool, struct workitem *item,
6868
typedef void (*thdpool_foreach_fn)(struct thdpool *pool, struct workitem *item,
6969
void *user);
7070
void thdpool_foreach(struct thdpool *pool, thdpool_foreach_fn, void *user);
71-
71+
typedef void (*thdpool_for_each_thd_fn)(struct thdpool *pool, pthread_t tid, int idle, void *thddata, void *user);
72+
void thdpool_for_each_thd(struct thdpool *pool, thdpool_for_each_thd_fn, void *user);
7273
struct thdpool *thdpool_create(const char *name, size_t per_thread_data_sz);
7374
int thdpool_destroy(struct thdpool **pool_p, int coopWaitUs);
7475
void thdpool_set_stack_size(struct thdpool *pool, size_t sz_bytes);

Diff for: bdb/bdb_thd_io.c

-23
Original file line numberDiff line numberDiff line change
@@ -156,29 +156,6 @@ static ssize_t bdb_write(int fd, const void *buf, size_t nbytes)
156156
return rc;
157157
}
158158

159-
void bdb_set_io_control(void (*start)(), void (*cmplt)())
160-
{
161-
logmsg(LOGMSG_DEBUG, "IO CONTROL disabled\n");
162-
if (1)
163-
return;
164-
#if 0
165-
io_start=start;
166-
io_cmplt=cmplt;
167-
168-
if
169-
(
170-
db_env_set_func_read(bdb_read) ||
171-
db_env_set_func_fsync(bdb_fsync) ||
172-
db_env_set_func_write(bdb_write)
173-
)
174-
{
175-
printf("**FAILED db_env_set_func_pread RC\n");
176-
abort();
177-
}
178-
printf("SET UP THD IO CONTROL\n");
179-
#endif
180-
}
181-
182159
void bdb_get_iostats(int *n_reads, int *l_reads, int *n_writes, int *l_writes)
183160
{
184161
*n_reads = norm_reads;

Diff for: db/comdb2.h

+4
Original file line numberDiff line numberDiff line change
@@ -1292,6 +1292,7 @@ struct osql_sess {
12921292
pthread_mutex_t participant_lk;
12931293
int is_done;
12941294
int is_sanctioned; /* set by fdb from coordinator-master */
1295+
int is_qconsume_only;
12951296
};
12961297
typedef struct osql_sess osql_sess_t;
12971298

@@ -1834,6 +1835,9 @@ extern int gbl_appsock_pooling;
18341835
extern struct thdpool *gbl_appsock_thdpool;
18351836
extern struct thdpool *gbl_osqlpfault_thdpool;
18361837
extern struct thdpool *gbl_udppfault_thdpool;
1838+
extern struct thdpool *gbl_handle_buf_write_thdpool;
1839+
extern struct thdpool *gbl_handle_buf_read_thdpool;
1840+
extern struct thdpool *gbl_handle_buf_queue_thdpool;
18371841

18381842
extern int gbl_consumer_rtcpu_check;
18391843
extern int gbl_node1rtcpuable;

Diff for: db/db_tunables.c

+2
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,8 @@ extern int gbl_sc_history_max_rows;
566566
extern int gbl_sc_status_max_rows;
567567
extern int gbl_rep_process_pstack_time;
568568
extern int gbl_sql_recover_time;
569+
extern int gbl_queue_use_dedicated_writers;
570+
extern int gbl_queue_max_dedicated_writers;
569571

570572
extern void set_snapshot_impl(snap_impl_enum impl);
571573
extern const char *snap_impl_str(snap_impl_enum impl);

Diff for: db/db_tunables.h

+2
Original file line numberDiff line numberDiff line change
@@ -2499,4 +2499,6 @@ REGISTER_TUNABLE("sc_status_max_rows", "Max number of rows returned in comdb2_sc
24992499
REGISTER_TUNABLE("rep_process_pstack_time", "pstack the server if rep_process runs longer than time specified in secs (Default: 30s)",
25002500
TUNABLE_INTEGER, &gbl_rep_process_pstack_time, 0, NULL, NULL, NULL, NULL);
25012501
REGISTER_TUNABLE("sql_recover_time", "Number of msec before checking if SQL has waiters. 0 will disable. (Default: 10ms)", TUNABLE_INTEGER, &gbl_sql_recover_time, 0, NULL, NULL, NULL, NULL);
2502+
REGISTER_TUNABLE("queue_use_dedicated_writers", "Whether queue-consumes are processed in dedicated writers. (Default: on)", TUNABLE_BOOLEAN, &gbl_queue_use_dedicated_writers, 0, NULL, NULL, NULL, NULL);
2503+
REGISTER_TUNABLE("queue_max_dedicated_writers", "Max number of dedicated queue-consume writers. (Default: on)", TUNABLE_INTEGER, &gbl_queue_max_dedicated_writers, 0, NULL, NULL, NULL, NULL);
25022504
#endif /* _DB_TUNABLES_H */

0 commit comments

Comments
 (0)