Skip to content

Commit 0b0e333

Browse files
committed
feat: veb
1 parent 300eedf commit 0b0e333

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+807
-421
lines changed

frameworks/V/pico.v/benchmark_config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@
2020
"display_name": "pico.v",
2121
"notes": "",
2222
"versus": "None"
23+
},
24+
"optimized": {
25+
"json_url": "/json",
26+
"plaintext_url": "/plaintext",
27+
"port": 8088,
28+
"approach": "Realistic",
29+
"classification": "Micro",
30+
"database": "None",
31+
"framework": "pico.v",
32+
"language": "V",
33+
"flavor": "None",
34+
"orm": "None",
35+
"platform": "None",
36+
"webserver": "None",
37+
"os": "Linux",
38+
"database_os": "Linux",
39+
"display_name": "pico.v",
40+
"notes": "",
41+
"versus": "None"
2342
}
2443
}
2544
]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM syou/v-dev:0.1
2+
3+
WORKDIR /app
4+
5+
COPY ./main.v run.sh ./
6+
7+
RUN git clone https://github.com/S-YOU/pico.v src && cd src && git checkout v0.0.4 \
8+
&& cd /app/src/picoev && git clone https://github.com/S-YOU/picoev src && cd src && git checkout v0.0.1 \
9+
&& cd /app/src/picohttpparser && git clone https://github.com/S-YOU/picohttpparser src && cd src && git checkout v0.0.1 \
10+
&& ln -s /app/src /root/.vmodules/syou \
11+
&& cd /app && v -prod -cflags '-std=gnu11 -Wall -O3 -march=native -mtune=native -flto' main.v
12+
13+
EXPOSE 8088
14+
15+
CMD sh run.sh

frameworks/V/pico.v/pico.v.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ RUN git clone https://github.com/S-YOU/pico.v src && cd src && git checkout v0.0
1212

1313
EXPOSE 8088
1414

15-
CMD sh run.sh
15+
CMD ./main
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"framework": "picoev",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Micro",
11+
"database": "None",
12+
"framework": "picoev",
13+
"language": "V",
14+
"flavor": "None",
15+
"orm": "None",
16+
"platform": "None",
17+
"webserver": "None",
18+
"os": "Linux",
19+
"database_os": "Linux",
20+
"display_name": "picoev",
21+
"notes": "",
22+
"versus": "None"
23+
},
24+
"optimized": {
25+
"json_url": "/json",
26+
"plaintext_url": "/plaintext",
27+
"port": 8080,
28+
"approach": "Realistic",
29+
"classification": "Micro",
30+
"database": "None",
31+
"framework": "picoev",
32+
"language": "V",
33+
"flavor": "None",
34+
"orm": "None",
35+
"platform": "None",
36+
"webserver": "None",
37+
"os": "Linux",
38+
"database_os": "Linux",
39+
"display_name": "picoev optimized",
40+
"notes": "",
41+
"versus": "None"
42+
}
43+
}
44+
]
45+
}

frameworks/V/picoev/main.v

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import json
2+
import picoev
3+
import picohttpparser
4+
5+
struct Message {
6+
message string
7+
}
8+
9+
@[inline]
10+
fn json_response(mut res picohttpparser.Response) string {
11+
msg := Message{
12+
message: 'Hello, World!'
13+
}
14+
header_ok(mut res)
15+
res.json()
16+
return json.encode(msg)
17+
}
18+
19+
@[inline]
20+
fn hello_response(mut res picohttpparser.Response) string {
21+
header_ok(mut res)
22+
res.plain()
23+
return 'Hello, World!'
24+
}
25+
26+
@[inline]
27+
fn index_response(mut res picohttpparser.Response) string {
28+
header_ok(mut res)
29+
res.html()
30+
return 'Hello!\n<a href="/plaintext">plaintext</a>\n<a href="/json">json</a>'
31+
}
32+
33+
fn callback(data voidptr, req picohttpparser.Request, mut res picohttpparser.Response) {
34+
if req.method == 'GET' {
35+
if req.path == '/plaintext' {
36+
res.body(hello_response(mut res))
37+
} else if req.path == '/json' {
38+
res.body(json_response(mut res))
39+
} else {
40+
res.body(index_response(mut res))
41+
}
42+
} else {
43+
res.http_404()
44+
}
45+
res.end()
46+
}
47+
48+
fn header_ok(mut res picohttpparser.Response) {
49+
res.http_ok()
50+
res.header_server()
51+
res.header_date()
52+
}
53+
54+
fn main() {
55+
config := picoev.Config{
56+
cb: callback
57+
}
58+
println('Starting webserver on http://localhost:${config.port}/ ...')
59+
mut server := picoev.new(config)!
60+
server.serve()
61+
}

frameworks/V/picoev/picoev

829 KB
Binary file not shown.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM thevlang/vlang:debian-dev
2+
3+
WORKDIR /app
4+
COPY ./main.v run.sh ./
5+
6+
RUN v -prod -o picoev .
7+
8+
EXPOSE 8080
9+
CMD sh ./run.sh
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM thevlang/vlang:debian-dev
2+
3+
WORKDIR /app
4+
COPY ./main.v run.sh ./
5+
6+
RUN v -prod -o picoev .
7+
8+
EXPOSE 8080
9+
CMD ./picoev
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
for i in $(seq 0 $(($(nproc --all)-1))); do
4-
taskset -c $i ./veb &
4+
taskset -c $i ./picoev &
55
done
66

77
wait

frameworks/V/veb/README.md

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,51 @@
1-
# [veb](https://modules.vlang.io/veb.html) Benchmarking Test
1+
# V lang example web server
22

3-
Veb is the default V language web framework. This test uses veb and V native ORM.
3+
Server "competition" *Web Framework Benchmarks*: https://www.techempower.com/benchmarks
44

5-
### Test Type Implementation Source Code
5+
It designed to demonstrate how to use <a href="https://modules.vlang.io/veb.html">Veb</a>'s built-in features to create a web application. It's a slightly more complex example due to the fact i tried to reuse code for multiple scenarios.
66

7-
All tests in a 95 lines [main.v] and a html [template](fortunes.html)
8-
### Database
7+
> NOTE: Cache test still to be properly implemented
98
10-
PostgresQL
9+
## Scenarios
1110

12-
## Test URLs
13-
### JSON
11+
We created some scenarios. One on each folder. All scenarios use **Veb** server, the <a href="https://vlang.io">V</a> lang built-in web framework.
1412

15-
http://localhost:8080/json
13+
Scenario | Run locally | Run inside Benchmark
14+
--- | --- | ---
15+
Veb with Postgres | `db_host="127.0.0.1" v run veb-pg/` | `./tfb --mode veb`
16+
Veb with Postgres and ORM | `db_host="127.0.0.1" v run veb-pg-orm/` | `./tfb --mode veb-pg-orm`
17+
Veb with MySQL/MariaDB | `db_host="127.0.0.1" v run veb-my/` | `./tfb --mode veb-my`
18+
Veb with MySQL/MariaDB and ORM | `db_host="127.0.0.1" v run veb-my-orm/` | `./tfb --mode veb-my-orm`
19+
Veb with Postgres (Optimized) | `db_host="127.0.0.1" v run veb-pg/` | `./tfb --mode veb-pg-optimized`
20+
Veb with Postgres (Compilation flags) | `db_host="127.0.0.1" v run veb-pg/` | `./tfb --mode veb-compilation`
1621

17-
### PLAINTEXT
22+
## Local Setup
1823

19-
http://localhost:8080/plaintext
24+
in order to test the servers locally, you will need a database server and a database client. using container, you can use:
2025

21-
### DB
26+
### Postgres:
2227

23-
http://localhost:8080/db
28+
```
29+
docker run --name benckmark-postgres \
30+
-e POSTGRES_USER=benchmarkdbuser \
31+
-e POSTGRES_PASSWORD=benchmarkdbpass \
32+
-e POSTGRES_DB=hello_world \
33+
-p 5432:5432 \
34+
-d techempower/postgres:latest
35+
```
2436

25-
### QUERY
37+
### MySQL/MariaDB:
2638

27-
http://localhost:8080/query?q=
39+
```
40+
docker run --name benckmark-mysql \
41+
-e MYSQL_ROOT_PASSWORD=benchmarkdbpass \
42+
-e MYSQL_USER=benchmarkdbuser \
43+
-e MYSQL_PASSWORD=benchmarkdbpass \
44+
-e MYSQL_DATABASE=hello_world \
45+
-p 3306:3306 \
46+
-d techempower/mysql:latest
47+
```
2848

29-
### UPDATE
49+
---
3050

31-
http://localhost:8080/update?queries=
32-
33-
### FORTUNES
34-
35-
http://localhost:8080/fortunes
51+
Created by Bruno Massa

0 commit comments

Comments
 (0)