Skip to content

Commit 8b5ee60

Browse files
authored
vlib: vanilla_http_server (#24202)
1 parent 711d7c4 commit 8b5ee60

6 files changed

Lines changed: 616 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing
2+
3+
## Rules
4+
5+
- Don't slow down performance
6+
- Always try to keep abstraction to a minimum
7+
- Don't complicate it
8+
9+
## Benchmarking & Testing
10+
11+
### CURL
12+
13+
```sh
14+
curl -X GET --verbose http://localhost:3000/ &&
15+
curl -X POST --verbose http://localhost:3000/user &&
16+
curl -X GET --verbose http://localhost:3000/user/1
17+
18+
```
19+
20+
### WRK
21+
22+
```sh
23+
wrk -H 'Connection: "keep-alive"' --connection 512 --threads 16 --duration 10s http://localhost:3000
24+
```
25+
26+
### Valgrind
27+
28+
```sh
29+
# Race condition check
30+
v -prod -gc none .
31+
valgrind --tool=helgrind ./vanilla
32+
```

‎vlib/vanilla_http_server/README.md‎

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<img src="./logo.png" alt="vanilla_http_server Logo" width="100">
2+
3+
# vanilla_http_server
4+
5+
- **Fast**: Multi-threaded, non-blocking I/O, lock-free, copy-free, epoll, SO_REUSEPORT.
6+
- **Thread Affinity**: Work in Progress (W.I.P.).
7+
- **Modular**: Compatible with any HTTP parser.
8+
- **Memory Safety**: No race conditions.
9+
- **No Magic**: Transparent and straightforward.
10+
- **E2E Testing**: Allows end-to-end testing and scripting without running the server.
11+
Simply pass the raw request to `handle_request()`.
12+
- **SSE Friendly**: Server-Sent Events support.
13+
- **Graceful Shutdown**: Work in Progress (W.I.P.).
14+
15+
## Installation
16+
17+
### From Root Directory
18+
19+
1. Create the required directories:
20+
21+
```bash
22+
mkdir -p ~/.vmodules/enghitalo/vanilla
23+
```
24+
25+
2. Copy the `vanilla_http_server` directory to the target location:
26+
27+
```bash
28+
cp -r ./ ~/.vmodules/enghitalo/vanilla
29+
```
30+
31+
3. Run the example:
32+
33+
```bash
34+
v -prod crun examples/simple
35+
```
36+
37+
This sets up the module in your `~/.vmodules` directory for use.
38+
39+
### From Repository
40+
41+
Install directly from the repository:
42+
43+
```bash
44+
v install https://github.com/enghitalo/vanilla_http_server
45+
```
46+
47+
## Benchmarking
48+
49+
Run the following commands to benchmark the server:
50+
51+
1. Test with `curl`:
52+
53+
```bash
54+
curl -v http://localhost:3001
55+
```
56+
57+
2. Test with `wrk`:
58+
59+
```bash
60+
wrk -H 'Connection: "keep-alive"' --connection 512 --threads 16 --duration 60s http://localhost:3001
61+
```
62+
63+
Example output:
64+
65+
```plaintext
66+
Running 1m test @ http://localhost:3001
67+
16 threads and 512 connections
68+
Thread Stats Avg Stdev Max +/- Stdev
69+
Latency 1.25ms 1.46ms 35.70ms 84.67%
70+
Req/Sec 32.08k 2.47k 57.85k 71.47%
71+
30662010 requests in 1.00m, 2.68GB read
72+
Requests/sec: 510197.97
73+
Transfer/sec: 45.74MB
74+
```

0 commit comments

Comments
 (0)