Skip to content

Commit b5e989c

Browse files
committed
add starter run script, and fix mist setup
1 parent 8dd7bf1 commit b5e989c

File tree

3 files changed

+36
-34
lines changed

3 files changed

+36
-34
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/output/

glench/src/glench.gleam

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,31 @@ import gleam/erlang
22
import gleam/http
33
import gleam/http/request.{Request}
44
import gleam/http/response
5-
import gleam/otp/actor
6-
import gleam/otp/process
7-
import glisten
8-
import glisten/tcp
95
import mist/http as mhttp
106
import mist
117

12-
pub external fn observer_start() -> Nil =
13-
"observer" "start"
14-
158
pub fn main() {
169
let empty_response =
1710
response.new(200)
1811
|> response.set_body(<<>>)
19-
|> mhttp.to_bit_builder
2012

2113
let not_found =
2214
response.new(404)
2315
|> response.set_body(<<>>)
2416

25-
// assert Ok(_) =
26-
// mist.serve(
27-
// 8080,
28-
// mhttp.handler(fn(req: Request(BitString)) {
29-
// case req.method, request.path_segments(req) {
30-
// http.Get, [] -> empty_response
31-
// http.Get, ["user", id] ->
32-
// response.new(200)
33-
// |> response.set_body(<<id:utf8>>)
34-
// http.Post, ["user"] -> empty_response
35-
// _, _ -> not_found
36-
// }
37-
// }),
38-
// )
39-
40-
assert Ok(_) = glisten.serve(
41-
8080,
42-
tcp.handler(fn(_msg, ws_state) {
43-
let #(socket, _state) = ws_state
44-
assert Ok(_) = tcp.send(socket, empty_response)
45-
actor.Stop(process.Normal)
46-
}),
47-
Nil
48-
)
49-
50-
// observer_start()
17+
assert Ok(_) =
18+
mist.serve(
19+
8080,
20+
mhttp.handler(fn(req: Request(BitString)) {
21+
case req.method, request.path_segments(req) {
22+
http.Get, [] -> empty_response
23+
http.Get, ["user", id] ->
24+
response.new(200)
25+
|> response.set_body(<<id:utf8>>)
26+
http.Post, ["user"] -> empty_response
27+
_, _ -> not_found
28+
}
29+
}),
30+
)
5131
erlang.sleep_forever()
5232
}

run.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
if [ -z "$1" ]; then
4+
echo "Need to pass output tag"
5+
exit 1
6+
fi
7+
8+
concurrencies=(1 2 4 6 8 12 16)
9+
10+
for concurrency in "${concurrencies[@]}"
11+
do
12+
echo "Running '/' with $concurrency concurrency..."
13+
ab -n 200000 -l -c $concurrency -e "output/$1-$concurrency.csv" http://localhost:8080/
14+
done
15+
16+
for concurrency in "${concurrencies[@]}"
17+
do
18+
echo "Running '/user/:id' with $concurrency concurrency..."
19+
random=$[$RANDOM % 2048 + 1024]
20+
ab -n 200000 -l -c $concurrency -e "output/$1-$concurrency-user-$random.csv" "http://localhost:8080/user/$random"
21+
done

0 commit comments

Comments
 (0)