Skip to content

Commit deddf29

Browse files
author
c-cesar
committed
Add veb. V lang default framework
1 parent 0c85506 commit deddf29

File tree

6 files changed

+228
-0
lines changed

6 files changed

+228
-0
lines changed

frameworks/V/veb/README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Congratulations!
2+
3+
You have successfully built a new test in the suite!
4+
5+
There are some remaining tasks to do before you are ready to open a pull request, however.
6+
7+
## Next Steps
8+
9+
1. Gather your source code.
10+
11+
You will need to ensure that your source code is beneath this directory. The most common solution is to include a `src` directory and place your source code there.
12+
13+
2. Edit `benchmark_config.json`
14+
15+
You will need alter `benchmark_config.json` to have the appropriate end-points and port specified.
16+
17+
3. Create `veb.dockerfile`
18+
19+
This is the dockerfile that is built into a docker image and run when a benchmark test is run. Specifically, this file tells the suite how to build and start your test application.
20+
21+
You can create multiple implementations and they will all conform to `[name in benchmark_config.json].dockerfile`. For example, the `default` implementation in `benchmark_config.json` will be `veb.dockerfile`, but if you wanted to make another implementation that did only the database tests for MySQL, you could make `veb-mysql.dockerfile` and have an entry in your `benchmark_config.json` for `veb-mysql`.
22+
23+
4. Test your application
24+
25+
$ tfb --mode verify --test veb
26+
27+
This will run the suite in `verify` mode for your test. This means that no benchmarks will be captured and we will test that we can hit your implementation end-points specified by `benchmark_config.json` and that the response is correct.
28+
29+
Once you are able to successfully run your test through our suite in this way **and** your test passes our validation, you may move on to the next step.
30+
31+
5. Add your test to `.github/workflows/build.yml`
32+
33+
Edit `.github/workflows/build.yml` to ensure that Github Actions will automatically run our verification tests against your new test. This file is kept in alphabetical order, so find where `TESTDIR=V/veb` should be inserted under `env > matrix` and put it there.
34+
35+
6. Fix this `README.md` and open a pull request
36+
37+
Starting on line 49 is your actual `README.md` that will sit with your test implementation. Update all the dummy values to their correct values so that when people visit your test in our Github repository, they will be greated with information on how your test implementation works and where to look for useful source code.
38+
39+
After you have the real `README.md` file in place, delete everything above line 59 and you are ready to open a pull request.
40+
41+
Thanks and Cheers!
42+
43+
44+
45+
46+
47+
48+
49+
# veb Benchmarking Test
50+
51+
### Test Type Implementation Source Code
52+
53+
* [JSON](Relative/Path/To/Your/Source/File)
54+
* [PLAINTEXT](Relative/Path/To/Your/Source/File)
55+
* [DB](Relative/Path/To/Your/Source/File)
56+
* [QUERY](Relative/Path/To/Your/Source/File)
57+
* [CACHED QUERY](Relative/Path/To/Your/Source/File)
58+
* [UPDATE](Relative/Path/To/Your/Source/File)
59+
* [FORTUNES](Relative/Path/To/Your/Source/File)
60+
61+
## Important Libraries
62+
The tests were run with:
63+
* [Software](https://www.example1.com/)
64+
* [Example](http://www.example2.com/)
65+
66+
## Test URLs
67+
### JSON
68+
69+
http://localhost:8080/json
70+
71+
### PLAINTEXT
72+
73+
http://localhost:8080/plaintext
74+
75+
### DB
76+
77+
http://localhost:8080/db
78+
79+
### QUERY
80+
81+
http://localhost:8080/query?queries=
82+
83+
### CACHED QUERY
84+
85+
http://localhost:8080/cached_query?queries=
86+
87+
### UPDATE
88+
89+
http://localhost:8080/update?queries=
90+
91+
### FORTUNES
92+
93+
http://localhost:8080/fortunes
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"framework": "veb",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"db_url": "/db",
9+
"port": 8080,
10+
"approach": "Realistic",
11+
"classification": "Fullstack",
12+
"database": "Postgres",
13+
"framework": "veb",
14+
"language": "V",
15+
"flavor": "None",
16+
"orm": "Full",
17+
"platform": "None",
18+
"webserver": "None",
19+
"os": "Linux",
20+
"database_os": "Linux",
21+
"display_name": "veb",
22+
"notes": "",
23+
"versus": "None"
24+
}
25+
}
26+
]
27+
}

frameworks/V/veb/config.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[framework]
2+
name = "veb"
3+
4+
[main]
5+
urls.plaintext = "/plaintext"
6+
urls.json = "/json"
7+
urls.db = "/db"
8+
approach = "Realistic"
9+
classification = "Fullstack"
10+
database = "Postgres"
11+
database_os = "Linux"
12+
os = "Linux"
13+
orm = "Full"
14+
platform = "None"
15+
webserver = "None"
16+
versus = "None"

frameworks/V/veb/main.v

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import veb
2+
import time
3+
import rand
4+
import db.pg
5+
6+
import log
7+
8+
pub struct Context {
9+
veb.Context
10+
}
11+
12+
pub struct App {
13+
pub mut:
14+
db pg.DB
15+
}
16+
17+
pub fn (app &App) plaintext(mut ctx Context) veb.Result {
18+
log.error('plain')
19+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
20+
ctx.set_header(.server, 'veb')
21+
return ctx.text('Hello, World!')
22+
}
23+
24+
pub fn (app &App) json(mut ctx Context) veb.Result {
25+
log.error('json')
26+
obj := {'message': 'Hello, World!'}
27+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
28+
ctx.set_header(.server, 'veb')
29+
return ctx.json(obj)
30+
}
31+
32+
struct World {
33+
id int @[primary; sql: serial]
34+
randomnumber int
35+
}
36+
37+
pub fn (app &App) db(mut ctx Context) veb.Result {
38+
r := rand.int_in_range(1, 10000) or { return ctx.text('rand error') }
39+
result := sql app.db {
40+
select from World where id == r
41+
} or { return ctx.text(app.db.last_id().str()) }
42+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
43+
ctx.set_header(.server, 'veb')
44+
return ctx.json({'id': r, 'randomNumber': result[0].randomnumber})
45+
}
46+
47+
fn main() {
48+
mut app := &App{
49+
db: pg.connect(pg.Config{
50+
host: 'tfb-database'
51+
port: 5432
52+
user: 'benchmarkdbuser'
53+
password: 'benchmarkdbpass'
54+
dbname: 'hello_world'
55+
}) !
56+
//db: pg.connect_with_conninfo('postgresql://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?sslmode=disable') !
57+
}
58+
veb.run[App, Context](mut app, 8080)
59+
}
60+
61+
/*
62+
pub fn (app &App) queries(mut ctx Context) veb.Result {
63+
return
64+
}
65+
66+
pub fn (app &App) updates(mut ctx Context) veb.Result {
67+
return
68+
}
69+
70+
pub fn (app &App) fortunes(mut ctx Context) veb.Result {
71+
return
72+
}
73+
*/

frameworks/V/veb/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
for i in $(seq 0 $(nproc --ignore=1)); do
4+
taskset -c $i ./main &
5+
done
6+
7+
wait

frameworks/V/veb/veb.dockerfile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM thevlang/vlang:debian-dev
2+
RUN apt update && apt install -y libpq-dev
3+
4+
# Compile veb
5+
WORKDIR /app
6+
COPY ./main.v run.sh ./
7+
RUN v -prod -cflags '-std=gnu11 -Wall -O3 -march=native -mtune=native -flto' main.v
8+
9+
# Run veb
10+
EXPOSE 8080
11+
CMD sh run.sh
12+
#CMD ./main

0 commit comments

Comments
 (0)