-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The changes include: Add patches for lwan. Add script to CMakelist.txt to link library. Add lwan-preload.c wrapper for lwan. Add send() system call to wrapper.c. Add demo and update README.md. When there is only one connection from the browser, only send() will be called. When there are multiple connections, send() will be called once and then sendfile() will be called. Close #20
- Loading branch information
1 parent
bfc0f27
commit f301405
Showing
10 changed files
with
224 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Timeout in seconds to keep a connection alive. | ||
keep_alive_timeout = 15 | ||
|
||
# Set to true to not print any debugging messages. (Only effective in | ||
# release builds.) | ||
quiet = false | ||
|
||
# Value of "Expires" header. Default is 1 month and 1 week. | ||
expires = 1M 1w | ||
|
||
# Number of I/O threads. Default (0) is number of online CPUs. | ||
threads = 1 | ||
|
||
# Disable HAProxy's PROXY protocol by default. Only enable if needed. | ||
proxy_protocol = false | ||
|
||
# Enable straitjacket by default. The `drop_capabilities` option is `true` | ||
# by default. Other options may require more privileges. | ||
straitjacket | ||
|
||
listener *:8080 | ||
|
||
site { | ||
serve_files / { | ||
# correct path will be replaced by our script | ||
path = /tmp/web | ||
# When requesting for file.ext, look for a smaller/newer file.ext.gz, | ||
# and serve that instead if `Accept-Encoding: gzip` is in the | ||
# request headers. | ||
serve precompressed files = true | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- old/lwan-master/src/bin/lwan/main.c 2022-06-05 08:53:47.000000000 +0800 | ||
+++ new/lwan-master/src/bin/lwan/main.c 2022-06-09 21:13:59.257682000 +0800 | ||
@@ -224,7 +224,7 @@ | ||
|
||
c = *lwan_get_default_config(); | ||
c.listener = strdup("*:8080"); | ||
- | ||
+ esca_init(); | ||
switch (parse_args(argc, argv, &c, root, &sj)) { | ||
case ARGS_SERVE_FILES: | ||
lwan_status_info("Serving files from %s", root); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- old/lwan-master/src/lib/lwan-thread.c 2022-06-05 08:53:47.000000000 +0800 | ||
+++ new/lwan-master/src/lib/lwan-thread.c 2022-06-09 21:18:31.790748000 +0800 | ||
@@ -924,7 +924,7 @@ | ||
break; | ||
continue; | ||
} | ||
- | ||
+ batch_start(); | ||
for (struct epoll_event *event = events; n_fds--; event++) { | ||
struct lwan_connection *conn = event->data.ptr; | ||
|
||
@@ -959,6 +959,7 @@ | ||
|
||
if (created_coros) | ||
timeouts_add(t->wheel, &tq.timeout, 1000); | ||
+ batch_flush(); | ||
} | ||
|
||
pthread_barrier_wait(&lwan->thread.barrier); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env bash | ||
libpath=$(find $(pwd) -type f -name "libshim.so" | sed 's_/_\\/_g') | ||
webpath=$(readlink --canonicalize web | sed 's_/_\\/_g') | ||
lwanpath=$1 | ||
# modify lwan | ||
sed -i "26s/path.*/path = ${webpath}/" configs/lwan.conf | ||
sed -i "37a add_library(libshim SHARED IMPORTED GLOBAL)\nset_target_properties(libshim PROPERTIES IMPORTED_LOCATION ${libpath})\nlist(APPEND ADDITIONAL_LIBRARIES libshim)" ${lwanpath}/CMakeLists.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Syscall wrapper for Effective System Call Aggregation (ESCA). | ||
* | ||
* Copyright (c) 2021-2022 National Cheng Kung University, Taiwan. | ||
* Authored by Yao Hwang <yaohwang99@gmail.com> | ||
*/ | ||
|
||
int close(int fd) | ||
{ | ||
if (!in_segment) { | ||
real_close = real_close ? real_close : dlsym(RTLD_NEXT, "close"); | ||
return real_close(fd); | ||
} | ||
|
||
batch_num++; | ||
int off = global_j << 6; | ||
|
||
btable[off + global_i].sysnum = 3; | ||
btable[off + global_i].rstatus = BENTRY_BUSY; | ||
btable[off + global_i].nargs = 1; | ||
btable[off + global_i].args[0] = fd; | ||
|
||
if (global_i == MAX_TABLE_SIZE - 1) { | ||
if (global_j == MAX_THREAD_NUM - 1) { | ||
global_j = 0; | ||
} else { | ||
global_j++; | ||
} | ||
global_i = 0; | ||
} else { | ||
global_i++; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
ssize_t sendfile64(int outfd, int infd, off_t *offset, size_t count) | ||
{ | ||
if (!in_segment) | ||
return real_sendfile(outfd, infd, offset, count); | ||
|
||
batch_num++; | ||
int off = global_j << 6; | ||
|
||
btable[off + global_i].sysnum = 40; | ||
btable[off + global_i].rstatus = BENTRY_BUSY; | ||
btable[off + global_i].nargs = 4; | ||
btable[off + global_i].args[0] = outfd; | ||
btable[off + global_i].args[1] = infd; | ||
btable[off + global_i].args[2] = offset; | ||
btable[off + global_i].args[3] = count; | ||
|
||
if (global_i == MAX_TABLE_SIZE - 1) { | ||
if (global_j == MAX_THREAD_NUM - 1) { | ||
global_j = 0; | ||
} else { | ||
global_j++; | ||
} | ||
global_i = 0; | ||
} else { | ||
global_i++; | ||
} | ||
|
||
/* assume always success */ | ||
return count; | ||
} | ||
|
||
ssize_t send(int sockfd, const void *buf, size_t len, int flags) | ||
{ | ||
if (!in_segment) | ||
return real_send(sockfd, buf, len, flags); | ||
|
||
batch_num++; | ||
int off = global_j << 6; | ||
|
||
btable[off + global_i].sysnum = 44; | ||
btable[off + global_i].rstatus = BENTRY_BUSY; | ||
btable[off + global_i].nargs = 6; | ||
btable[off + global_i].args[0] = sockfd; | ||
btable[off + global_i].args[1] = buf; | ||
btable[off + global_i].args[2] = len; | ||
btable[off + global_i].args[3] = flags; | ||
btable[off + global_i].args[4] = NULL; | ||
btable[off + global_i].args[5] = 0; | ||
|
||
if (global_i == MAX_TABLE_SIZE - 1) { | ||
if (global_j == MAX_THREAD_NUM - 1) { | ||
global_j = 0; | ||
} else { | ||
global_j++; | ||
} | ||
global_i = 0; | ||
} else { | ||
global_i++; | ||
} | ||
|
||
/* assume always success */ | ||
return len; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters