File tree Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Expand file tree Collapse file tree 3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ epoll: epoll-server.c
17
17
# $(CC) $(CFLAGS) -o $@ $< -DFILE2_DEFINE -DADDITIONAL_FLAG
18
18
19
19
uring : uring-server.c
20
- $(CC ) -o uring-server uring-server.c request-handle.c cpu-bound.c $(CFLAGS ) -I/usr/local/include -L/usr/local/lib -luring
20
+ $(CC ) -o uring-server uring-server.c threadpool.c request-handle.c cpu-bound.c $(CFLAGS ) -pthread -I/usr/local/include -L/usr/local/lib -luring
21
21
# # $(CC) $(CFLAGS) -g -o $@ $< -DFILE3_DEFINE -lm
22
22
# # musl-gcc -o rest_server rest_server.c -I/usr/local/include -L/usr/local/lib -luring
23
23
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ This is a implementation of Http server using Linux SystemCalls.
4
4
5
5
There are some implementations:
6
6
- simple-server.c: Using only accept syscall.
7
- - epoll-server.c: Using epoll syscall with 10 events.
7
+ - epoll-server.c: Using epoll syscall with 1000 events.
8
8
- uring-server.c: Using io_uring (liburing) with queue depth 256.
9
9
10
10
### Default port is 8080.
Original file line number Diff line number Diff line change 14
14
#define QUEUE_DEPTH 256
15
15
#define READ_SZ 8192
16
16
#define BUFFER_SIZE 2048
17
+ #define WORKERS 3
17
18
18
19
#define EVENT_TYPE_ACCEPT 0
19
20
#define EVENT_TYPE_READ 1
@@ -31,6 +32,8 @@ struct request {
31
32
32
33
struct io_uring ring ;
33
34
35
+ ThreadPool pool ;
36
+
34
37
/*
35
38
One function that prints the system call and the error details
36
39
and then exits with error code 1. Non-zero meaning things didn't go well.
@@ -173,7 +176,8 @@ int handle_client_request(struct request *req) {
173
176
strncpy (args -> buffer , http_request , BUFFER_SIZE - 1 );
174
177
args -> buffer [BUFFER_SIZE - 1 ] = '\0' ;
175
178
176
- handle_request (args );
179
+ //handle_request(args); //sync
180
+ thread_pool_add (& pool , handle_request , args ); //async
177
181
return 0 ;
178
182
}
179
183
@@ -182,6 +186,8 @@ void server_loop(int server_socket) {
182
186
struct sockaddr_in client_addr ;
183
187
socklen_t client_addr_len = sizeof (client_addr );
184
188
189
+ thread_pool_init (& pool , WORKERS , QUEUE_DEPTH );
190
+
185
191
add_accept_request (server_socket , & client_addr , & client_addr_len );
186
192
187
193
while (1 ) {
You can’t perform that action at this time.
0 commit comments