Skip to content

Commit

Permalink
Fix bugs of non-squential workers
Browse files Browse the repository at this point in the history
  • Loading branch information
eecheng87 committed Feb 20, 2022
1 parent e9cca10 commit 9673a05
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 22 deletions.
4 changes: 2 additions & 2 deletions module/include/esca.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#define MAX_TABLE_ENTRY 64
#define MAX_TABLE_LEN 1
#define MAX_USR_WORKER 2
#define MAX_CPU_NUM 4
#define MAX_USR_WORKER 4
#define MAX_CPU_NUM 8
#define RATIO (MAX_CPU_NUM / MAX_USR_WORKER)
#define DEFAULT_IDLE_TIME 1500 /* in msec */

Expand Down
51 changes: 41 additions & 10 deletions patches/lighttpd.patch
Original file line number Diff line number Diff line change
@@ -1,28 +1,59 @@
diff --color -Naur old/server.c new/server.c
--- old/lighttpd1.4-lighttpd-1.4.56/src/server.c 2020-11-30 05:31:14.000000000 +0800
+++ new/lighttpd1.4-lighttpd-1.4.56/src/server.c 2022-02-02 15:17:33.789539164 +0800
@@ -1547,6 +1547,7 @@
+++ new/lighttpd1.4-lighttpd-1.4.56/src/server.c 2022-02-20 18:48:35.802869303 +0800
@@ -1165,7 +1165,7 @@
return -1;
}
}
-
+#if 0
/* close stdin and stdout, as they are not needed */
{
struct stat st;
@@ -1198,7 +1198,7 @@
if (devnull != errfd) close(devnull);
#endif
}
-
+#endif
http_response_send_1xx_cb_set(NULL, HTTP_VERSION_2);
if (srv->srvconf.feature_flags
&& !config_plugin_value_tobool(
@@ -1529,7 +1529,7 @@
log_error(srv->errh, __FILE__, __LINE__,
"server idle time limit command line option disables server.max-worker config file option.");
}
-
+int lighty_worker_index = -1;
/* start watcher and workers */
num_childs = srv->srvconf.max_worker;
if (num_childs > 0) {
@@ -1542,10 +1542,12 @@
server_graceful_signal_prev_generation();
while (!child && !srv_shutdown && !graceful_shutdown) {
if (num_childs > 0) {
+ lighty_worker_index++;
switch ((pid = fork())) {
case -1:
return -1;
case 0:
+ init_worker(lighty_worker_index);
child = 1;
+ init_worker(getpid());
alarm(0);
break;
default:
@@ -1904,7 +1905,7 @@
@@ -1904,7 +1906,7 @@
}

connections * const joblist = connection_joblist;
-
+batch_start();
if (fdevent_poll(srv->ev, joblist->used ? 0 : 1000) > 0) {
last_active_ts = log_epoch_secs;
}
@@ -1914,6 +1915,7 @@
@@ -1914,6 +1916,7 @@
: &srv->joblist_A;

server_run_con_queue(joblist);
+batch_flush();
}
}

18 changes: 8 additions & 10 deletions wrapper/preload.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,30 @@ int this_worker_id;
/* user worker can't touch worker's table in diff. set */
esca_table_t* table[MAX_CPU_NUM];

void init_worker(int pid)
void init_worker(int idx)
{
in_segment = 0;
batch_num = 0;
syscall_num = 0;

/* expect id = 0 ~ MAX_USR_WORKER - 1 */
/* FIXME: consider pid might not in sequence */
int id = pid - main_pid - 1;
this_worker_id = id;
/* expect idx = 0 ~ MAX_USR_WORKER - 1 */
this_worker_id = idx;

printf("Create worker ID = %d, pid = %d\n", id, getpid());
printf("Create worker ID = %d, pid = %d\n", this_worker_id, getpid());

if (id >= MAX_USR_WORKER) {
if (idx >= MAX_USR_WORKER) {
printf("[ERROR] Process exceed limit\n");
goto init_worker_exit;
}

int set_index = 0;
for (int i = id * RATIO; i < id * RATIO + RATIO; i++) {
for (int i = idx * RATIO; i < idx * RATIO + RATIO; i++) {
/* headers in same set using a same page */
esca_table_t* header = NULL;
if (i == id * RATIO) {
if (i == idx * RATIO) {
header = table[i] = (esca_table_t*)aligned_alloc(pgsize, pgsize);
}
table[i] = table[id * RATIO] + (i - id * RATIO);
table[i] = table[idx * RATIO] + (i - idx * RATIO);

/* allocate tables */
esca_table_entry_t* alloc = (esca_table_entry_t*)aligned_alloc(pgsize, pgsize * MAX_TABLE_LEN);
Expand Down

0 comments on commit 9673a05

Please sign in to comment.