Skip to content

Commit aabae50

Browse files
authored
Merge pull request #2 from felipeagger/feat/uring-ok
added thread pool on uring server.
2 parents cc00bd0 + 6a7a5d0 commit aabae50

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ epoll: epoll-server.c
1717
# $(CC) $(CFLAGS) -o $@ $< -DFILE2_DEFINE -DADDITIONAL_FLAG
1818

1919
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
2121
# # $(CC) $(CFLAGS) -g -o $@ $< -DFILE3_DEFINE -lm
2222
# # musl-gcc -o rest_server rest_server.c -I/usr/local/include -L/usr/local/lib -luring
2323

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is a implementation of Http server using Linux SystemCalls.
44

55
There are some implementations:
66
- 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.
88
- uring-server.c: Using io_uring (liburing) with queue depth 256.
99

1010
### Default port is 8080.

uring-server.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define QUEUE_DEPTH 256
1515
#define READ_SZ 8192
1616
#define BUFFER_SIZE 2048
17+
#define WORKERS 3
1718

1819
#define EVENT_TYPE_ACCEPT 0
1920
#define EVENT_TYPE_READ 1
@@ -31,6 +32,8 @@ struct request {
3132

3233
struct io_uring ring;
3334

35+
ThreadPool pool;
36+
3437
/*
3538
One function that prints the system call and the error details
3639
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) {
173176
strncpy(args->buffer, http_request, BUFFER_SIZE - 1);
174177
args->buffer[BUFFER_SIZE - 1] = '\0';
175178

176-
handle_request(args);
179+
//handle_request(args); //sync
180+
thread_pool_add(&pool, handle_request, args); //async
177181
return 0;
178182
}
179183

@@ -182,6 +186,8 @@ void server_loop(int server_socket) {
182186
struct sockaddr_in client_addr;
183187
socklen_t client_addr_len = sizeof(client_addr);
184188

189+
thread_pool_init(&pool, WORKERS, QUEUE_DEPTH);
190+
185191
add_accept_request(server_socket, &client_addr, &client_addr_len);
186192

187193
while (1) {

0 commit comments

Comments
 (0)