Przeglądaj źródła

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]>
donavindebartolo 4 lat temu
rodzic
commit
911b86da06

+ 11 - 0
frameworks/Julia/Jewelia/Project.toml

@@ -0,0 +1,11 @@
+[deps]
+HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
+JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
+MySQL = "39abe10b-433b-5dbd-92d4-e302a9df00cd"
+StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
+
+[compat]
+HTTP = "^0.9.14"
+JSON3 = "^1.9.1"
+MySQL = "^1.2.1"
+StructTypes = "^1.7.3"

+ 13 - 0
frameworks/Julia/Jewelia/README.md

@@ -0,0 +1,13 @@
+# Jewelia Benchmark Test
+
+[![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)
+
+This is a submission for [TechEmpower Framework Benchmarks (TFB)](http://www.techempower.com/benchmarks/) using the [Julia](https://julialang.org/) language.
+
+All tests are located in [julia_server.jl](https://github.com/donavindebartolo/FrameworkBenchmarks/tree/master/frameworks/Julia/Jewelia).
+
+### Implemented benchmarks
+- [x] JSON serialization
+- [x] Single query
+- [x] Multiple queries
+- [x] Plaintext

+ 26 - 0
frameworks/Julia/Jewelia/benchmark_config.json

@@ -0,0 +1,26 @@
+{
+    "framework": "jewelia",
+    "tests": [{
+      "default": {
+        "json_url": "/json",
+        "plaintext_url": "/plaintext",
+        "db_url": "/db",
+        "query_url": "/queries?queries=",
+        "port": 8080,
+        "approach": "Realistic",
+        "classification": "None",
+        "database": "MySQL",
+        "framework": "Jewelia",
+        "language": "Julia",
+        "flavor": "None",
+        "orm": "Raw",
+        "platform": "None",
+        "webserver": "HTTP.jl",
+        "os": "Linux",
+        "database_os": "Linux",
+        "display_name": "Jewelia",
+        "notes": "",
+        "versus": "None"
+      }
+    }]
+}

+ 22 - 0
frameworks/Julia/Jewelia/jewelia.dockerfile

@@ -0,0 +1,22 @@
+FROM ubuntu:latest
+
+ENV DEBIAN_FRONTEND noninteractive
+
+RUN apt-get update -yqq && apt-get install -y
+RUN apt-get update -yqq && apt-get install -y wget
+
+RUN wget https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.2-linux-x86_64.tar.gz
+RUN tar zxvf julia-1.6.2-linux-x86_64.tar.gz
+ENV PATH="$PATH:/julia-1.6.2/bin"
+
+RUN rm -f julia-1.6.2-linux-x86_64.tar.gz
+
+COPY ./ ./
+
+RUN julia -e 'import Pkg; Pkg.activate(@__DIR__); Pkg.instantiate()' && julia -e 'import Pkg; Pkg.activate(@__DIR__); Pkg.precompile()'
+
+RUN chmod +x run.sh
+
+EXPOSE 8080
+
+CMD ./run.sh

+ 92 - 0
frameworks/Julia/Jewelia/julia_server.jl

@@ -0,0 +1,92 @@
+using Pkg
+Pkg.activate(@__DIR__)
+
+using Dates
+using HTTP
+using MySQL
+using JSON3
+using StructTypes
+
+struct jsonObj
+    id::Int
+    randomNumber::Int
+end
+
+StructTypes.StructType(::Type{jsonObj}) = StructTypes.Struct()
+
+HTTP.listen("0.0.0.0" , 8080, reuseaddr = true) do http
+    target = http.message.target
+
+    HTTP.setstatus(http, 200)
+    HTTP.setheader(http, "Server" => "Julia-HTTP")
+    HTTP.setheader(http, "Date" => Dates.format(Dates.now(), Dates.RFC1123Format) * " GMT")
+
+    if endswith(target, "/plaintext")
+        HTTP.setheader(http, "Content-Type" => "text/plain")
+        HTTP.startwrite(http)
+        write(http, "Hello, World!")
+
+    elseif endswith(target, "/json")
+        HTTP.setheader(http, "Content-Type" => "application/json")
+        startwrite(http)
+        JSON3.write(http, (;message = "Hello, World!"))
+
+    elseif endswith(target, "/db")
+        HTTP.setheader(http, "Content-Type" => "application/json")
+        randNum = rand(1:10000)
+
+        conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
+        sqlQuery = "SELECT * FROM World WHERE id = $randNum"
+        results = DBInterface.execute(conn, sqlQuery)
+        row = first(results)
+        dbNumber = row[2]
+        jsonString = "{\"id\":$randNum,\"randomNumber\":$dbNumber}"
+
+        startwrite(http)
+        JSON3.write(http, (JSON3.read(jsonString)))
+
+    elseif occursin("/queries", target)
+        HTTP.setheader(http, "Content-Type" => "application/json")
+        numQueries = -1
+
+        try
+            numQueries = parse(Int64, (split(target, "="))[2])
+
+        catch ArgumentError
+            numQueries = 1
+
+        finally
+            if numQueries > 500
+                numQueries = 500
+            end
+
+            if numQueries < 1
+                numQueries = 1
+            end
+        end
+
+        # randNumList = rand(Int64, 1:10000, numQueries)
+        conn = DBInterface.connect(MySQL.Connection, "tfb-database", "benchmarkdbuser", "benchmarkdbpass", db="hello_world")
+
+        responseArray = Array{jsonObj}(undef, numQueries)
+        for i in 1:numQueries
+            # randNum = randNumList[i]
+            randNum = rand(1:10000)
+            sqlQuery = "SELECT * FROM World WHERE id = $randNum"
+            results = DBInterface.execute(conn, sqlQuery)
+            row = first(results)
+            dbNumber = row[2]
+            responseArray[i] = JSON3.read("{\"id\":$randNum,\"randomNumber\":$dbNumber}", jsonObj)
+        end
+
+        startwrite(http)
+        JSON3.write(http, responseArray)
+        # JSON3.write(http, (JSON3.read(responseArray, JSON3.Array)))
+
+    else
+        HTTP.setstatus(http, 404)
+        startwrite(http)
+        write(http, "Not Found")
+
+    end
+end

+ 5 - 0
frameworks/Julia/Jewelia/run.sh

@@ -0,0 +1,5 @@
+for i in $(seq 0 $(($(nproc --all)-1)));
+	do julia --threads auto julia_server.jl &
+	done
+
+while : ; do sleep 1 ; done