Skip to content

Commit 911b86d

Browse files
donavindebartoloabrowaoJayenn
authored
Jewelia : Plaintext, JSON Serialization, Single Database Query, Multiple Database Queries (#6829)
* Dockerfile test * fix run.sh * Working Docker build and plaintext/json tests implemented and passing.. * julia_server.jl patch * Update julia_server.jl Added test for Single Database Query * Update benchmark_config.json Updated to reflect addition of SDQ test * Update julia_server.jl Now sends JSON object instead of string. Packages have also been fixed. Single Query Test is now passing!!!! * Testing multiple db queries test * Testing multiple db queries test * multiple db queries response formatting changes * benchmark_config updates * More multiple queries formatting * Exception handling for multiple queries * More handling... * More handling * Even more exception handling..... * Exception handling for multiple queries test * Exception handling for 0 * Condensing exception handling for multi db queries * Exception handling fixes... * exception changes * Rand num changes * Rand num changes * Array changes * Added StructTypes * struct fix * test * revert test * Fix reduncancy/formatting code... * Fixed response headers * Update README.md * Update README.md * Create README.md Co-authored-by: abrowao <[email protected]> Co-authored-by: Jayenn <[email protected]>
1 parent e493709 commit 911b86d

File tree

6 files changed

+169
-0
lines changed

6 files changed

+169
-0
lines changed

frameworks/Julia/Jewelia/Project.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[deps]
2+
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
3+
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
4+
MySQL = "39abe10b-433b-5dbd-92d4-e302a9df00cd"
5+
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
6+
7+
[compat]
8+
HTTP = "^0.9.14"
9+
JSON3 = "^1.9.1"
10+
MySQL = "^1.2.1"
11+
StructTypes = "^1.7.3"

frameworks/Julia/Jewelia/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Jewelia Benchmark Test
2+
3+
[![Build Status](https://github.com/TechEmpower/FrameworkBenchmarks/workflows/build/badge.svg?branch=master&event=push)](https://github.com/TechEmpower/FrameworkBenchmarks/actions?query=workflow%3Abuild+branch%3Amaster)
4+
5+
This is a submission for [TechEmpower Framework Benchmarks (TFB)](http://www.techempower.com/benchmarks/) using the [Julia](https://julialang.org/) language.
6+
7+
All tests are located in [julia_server.jl](https://github.com/donavindebartolo/FrameworkBenchmarks/tree/master/frameworks/Julia/Jewelia).
8+
9+
### Implemented benchmarks
10+
- [x] JSON serialization
11+
- [x] Single query
12+
- [x] Multiple queries
13+
- [x] Plaintext
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"framework": "jewelia",
3+
"tests": [{
4+
"default": {
5+
"json_url": "/json",
6+
"plaintext_url": "/plaintext",
7+
"db_url": "/db",
8+
"query_url": "/queries?queries=",
9+
"port": 8080,
10+
"approach": "Realistic",
11+
"classification": "None",
12+
"database": "MySQL",
13+
"framework": "Jewelia",
14+
"language": "Julia",
15+
"flavor": "None",
16+
"orm": "Raw",
17+
"platform": "None",
18+
"webserver": "HTTP.jl",
19+
"os": "Linux",
20+
"database_os": "Linux",
21+
"display_name": "Jewelia",
22+
"notes": "",
23+
"versus": "None"
24+
}
25+
}]
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM ubuntu:latest
2+
3+
ENV DEBIAN_FRONTEND noninteractive
4+
5+
RUN apt-get update -yqq && apt-get install -y
6+
RUN apt-get update -yqq && apt-get install -y wget
7+
8+
RUN wget https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.2-linux-x86_64.tar.gz
9+
RUN tar zxvf julia-1.6.2-linux-x86_64.tar.gz
10+
ENV PATH="$PATH:/julia-1.6.2/bin"
11+
12+
RUN rm -f julia-1.6.2-linux-x86_64.tar.gz
13+
14+
COPY ./ ./
15+
16+
RUN julia -e 'import Pkg; Pkg.activate(@__DIR__); Pkg.instantiate()' && julia -e 'import Pkg; Pkg.activate(@__DIR__); Pkg.precompile()'
17+
18+
RUN chmod +x run.sh
19+
20+
EXPOSE 8080
21+
22+
CMD ./run.sh
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using Pkg
2+
Pkg.activate(@__DIR__)
3+
4+
using Dates
5+
using HTTP
6+
using MySQL
7+
using JSON3
8+
using StructTypes
9+
10+
struct jsonObj
11+
id::Int
12+
randomNumber::Int
13+
end
14+
15+
StructTypes.StructType(::Type{jsonObj}) = StructTypes.Struct()
16+
17+
HTTP.listen("0.0.0.0" , 8080, reuseaddr = true) do http
18+
target = http.message.target
19+
20+
HTTP.setstatus(http, 200)
21+
HTTP.setheader(http, "Server" => "Julia-HTTP")
22+
HTTP.setheader(http, "Date" => Dates.format(Dates.now(), Dates.RFC1123Format) * " GMT")
23+
24+
if endswith(target, "/plaintext")
25+
HTTP.setheader(http, "Content-Type" => "text/plain")
26+
HTTP.startwrite(http)
27+
write(http, "Hello, World!")
28+
29+
elseif endswith(target, "/json")
30+
HTTP.setheader(http, "Content-Type" => "application/json")
31+
startwrite(http)
32+
JSON3.write(http, (;message = "Hello, World!"))
33+
34+
elseif endswith(target, "/db")
35+
HTTP.setheader(http, "Content-Type" => "application/json")
36+
randNum = rand(1:10000)
37+
38+
conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
39+
sqlQuery = "SELECT * FROM World WHERE id = $randNum"
40+
results = DBInterface.execute(conn, sqlQuery)
41+
row = first(results)
42+
dbNumber = row[2]
43+
jsonString = "{\"id\":$randNum,\"randomNumber\":$dbNumber}"
44+
45+
startwrite(http)
46+
JSON3.write(http, (JSON3.read(jsonString)))
47+
48+
elseif occursin("/queries", target)
49+
HTTP.setheader(http, "Content-Type" => "application/json")
50+
numQueries = -1
51+
52+
try
53+
numQueries = parse(Int64, (split(target, "="))[2])
54+
55+
catch ArgumentError
56+
numQueries = 1
57+
58+
finally
59+
if numQueries > 500
60+
numQueries = 500
61+
end
62+
63+
if numQueries < 1
64+
numQueries = 1
65+
end
66+
end
67+
68+
# randNumList = rand(Int64, 1:10000, numQueries)
69+
conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
70+
71+
responseArray = Array{jsonObj}(undef, numQueries)
72+
for i in 1:numQueries
73+
# randNum = randNumList[i]
74+
randNum = rand(1:10000)
75+
sqlQuery = "SELECT * FROM World WHERE id = $randNum"
76+
results = DBInterface.execute(conn, sqlQuery)
77+
row = first(results)
78+
dbNumber = row[2]
79+
responseArray[i] = JSON3.read("{\"id\":$randNum,\"randomNumber\":$dbNumber}", jsonObj)
80+
end
81+
82+
startwrite(http)
83+
JSON3.write(http, responseArray)
84+
# JSON3.write(http, (JSON3.read(responseArray, JSON3.Array)))
85+
86+
else
87+
HTTP.setstatus(http, 404)
88+
startwrite(http)
89+
write(http, "Not Found")
90+
91+
end
92+
end

frameworks/Julia/Jewelia/run.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
for i in $(seq 0 $(($(nproc --all)-1)));
2+
do julia --threads auto julia_server.jl &
3+
done
4+
5+
while : ; do sleep 1 ; done

0 commit comments

Comments
 (0)