Skip to content

Commit c5204ed

Browse files
author
c-cesar
committed
Update Readme, config and so
1 parent deddf29 commit c5204ed

File tree

5 files changed

+71
-93
lines changed

5 files changed

+71
-93
lines changed

frameworks/V/veb/README.md

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,13 @@
1-
# Congratulations!
1+
# [veb](https://modules.vlang.io/veb.html) Benchmarking Test
22

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
3+
Veb is the default V language web framework. This test uses veb and V native ORM.
504

515
### Test Type Implementation Source Code
526

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)
7+
All tests in a 95 lines [main.v] and a html [template](fortunes.html)
8+
### Database
609

61-
## Important Libraries
62-
The tests were run with:
63-
* [Software](https://www.example1.com/)
64-
* [Example](http://www.example2.com/)
10+
PostgresQL
6511

6612
## Test URLs
6713
### JSON
@@ -78,11 +24,7 @@ http://localhost:8080/db
7824

7925
### QUERY
8026

81-
http://localhost:8080/query?queries=
82-
83-
### CACHED QUERY
84-
85-
http://localhost:8080/cached_query?queries=
27+
http://localhost:8080/query?q=
8628

8729
### UPDATE
8830

frameworks/V/veb/benchmark_config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
"json_url": "/json",
77
"plaintext_url": "/plaintext",
88
"db_url": "/db",
9+
"query_url": "/queries?q=",
10+
"fortune_url": "/fortunes",
11+
"update_url": "/update?q=",
912
"port": 8080,
1013
"approach": "Realistic",
1114
"classification": "Fullstack",
1215
"database": "Postgres",
1316
"framework": "veb",
1417
"language": "V",
1518
"flavor": "None",
16-
"orm": "Full",
19+
"orm": "Micro",
1720
"platform": "None",
1821
"webserver": "None",
1922
"os": "Linux",

frameworks/V/veb/config.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ name = "veb"
55
urls.plaintext = "/plaintext"
66
urls.json = "/json"
77
urls.db = "/db"
8+
urls.query = "/queries?q="
9+
urls.update = "/update?q="
10+
urls.fortune = "/fortunes"
811
approach = "Realistic"
912
classification = "Fullstack"
1013
database = "Postgres"
1114
database_os = "Linux"
1215
os = "Linux"
13-
orm = "Full"
16+
orm = "Micro"
1417
platform = "None"
1518
webserver = "None"
1619
versus = "None"

frameworks/V/veb/main.v

Lines changed: 56 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import time
33
import rand
44
import db.pg
55

6-
import log
7-
86
pub struct Context {
97
veb.Context
108
}
@@ -15,14 +13,12 @@ pub mut:
1513
}
1614

1715
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')
16+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
2017
ctx.set_header(.server, 'veb')
2118
return ctx.text('Hello, World!')
2219
}
2320

2421
pub fn (app &App) json(mut ctx Context) veb.Result {
25-
log.error('json')
2622
obj := {'message': 'Hello, World!'}
2723
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
2824
ctx.set_header(.server, 'veb')
@@ -31,17 +27,69 @@ pub fn (app &App) json(mut ctx Context) veb.Result {
3127

3228
struct World {
3329
id int @[primary; sql: serial]
30+
mut:
3431
randomnumber int
3532
}
3633

3734
pub fn (app &App) db(mut ctx Context) veb.Result {
3835
r := rand.int_in_range(1, 10000) or { return ctx.text('rand error') }
39-
result := sql app.db {
36+
mut world := sql app.db {
4037
select from World where id == r
41-
} or { return ctx.text(app.db.last_id().str()) }
38+
} or { return ctx.text('db error') }
39+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
40+
ctx.set_header(.server, 'veb')
41+
return ctx.json(world.first())
42+
}
43+
44+
pub fn (app &App) queries(mut ctx Context) veb.Result {
45+
mut q := ctx.query['q'].int()
46+
if q < 1 { q = 1 } else if q > 500 { q = 500 }
47+
mut world := []World{}
48+
for _ in 0..q {
49+
r := rand.int_in_range(1, 10000) or { return ctx.text('rand error') }
50+
world << sql app.db {
51+
select from World where id == r
52+
} or { return ctx.text('db error') }
53+
}
54+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
55+
ctx.set_header(.server, 'veb')
56+
return ctx.json(world)
57+
}
58+
59+
pub fn (app &App) update(mut ctx Context) veb.Result {
60+
mut q := ctx.query['q'].int()
61+
if q < 1 { q = 1 } else if q > 500 { q = 500 }
62+
mut world := []World{}
63+
for _ in 0..q {
64+
r := rand.int_in_range(1, 10000) or { return ctx.text('rand error') }
65+
world << sql app.db {
66+
select from World where id == r
67+
} or { return ctx.text('db error') }
68+
world.last().randomnumber = rand.int_in_range(1, 10000) or { return ctx.text('rand error') }
69+
sql app.db {
70+
update World set randomnumber = world.last().randomnumber where id == world.last().id
71+
} or { return ctx.text('db error') }
72+
}
73+
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
74+
ctx.set_header(.server, 'veb')
75+
return ctx.json(world)
76+
}
77+
78+
struct Fortune {
79+
id int @[primary; sql: serial]
80+
message string
81+
}
82+
83+
pub fn (app &App) fortunes(mut ctx Context) veb.Result {
84+
mut fortunes := sql app.db {
85+
select from Fortune
86+
} or { return ctx.text('db error') }
87+
fortunes.insert(0, Fortune{id: 0, message: 'Additional fortune added at request time.'})
88+
fortunes.sort(a.message < b.message)
4289
ctx.set_header(.date, time.now().as_utc().custom_format('ddd, DD MMM YYYY HH:MM:ss') + ' GMT')
4390
ctx.set_header(.server, 'veb')
44-
return ctx.json({'id': r, 'randomNumber': result[0].randomnumber})
91+
ctx.content_type = 'text/html; charset=utf-8'
92+
return $veb.html()
4593
}
4694

4795
fn main() {
@@ -53,21 +101,6 @@ fn main() {
53101
password: 'benchmarkdbpass'
54102
dbname: 'hello_world'
55103
}) !
56-
//db: pg.connect_with_conninfo('postgresql://benchmarkdbuser:benchmarkdbpass@tfb-database:5432/hello_world?sslmode=disable') !
57104
}
58105
veb.run[App, Context](mut app, 8080)
59106
}
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/veb.dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
FROM thevlang/vlang:debian-dev
22
RUN apt update && apt install -y libpq-dev
33

4-
# Compile veb
54
WORKDIR /app
6-
COPY ./main.v run.sh ./
5+
COPY ./main.v run.sh fortunes.html ./
76
RUN v -prod -cflags '-std=gnu11 -Wall -O3 -march=native -mtune=native -flto' main.v
87

9-
# Run veb
108
EXPOSE 8080
119
CMD sh run.sh
12-
#CMD ./main

0 commit comments

Comments
 (0)