Skip to content

Commit

Permalink
graphene: init
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillich committed Apr 7, 2022
1 parent 2ad2741 commit 6cbae02
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 10 deletions.
6 changes: 3 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ARG VARIANT="buster"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}

RUN apt-get update \
&& apt-get install -y libgit2-dev xz-utils \
&& apt-get install -y libgit2-dev xz-utils python3-pip \
&& curl -fsSL https://crystal-lang.org/install.sh | bash \
&& mkdir -p /etc/nix \
&& bash -c "printf \"sandbox = false\" > /etc/nix/nix.conf"
Expand All @@ -16,5 +16,5 @@ ENV USER=vscode

RUN bash -c "sh <(curl -L https://releases.nixos.org/nix/nix-2.6.1/install) --no-daemon" \
&& . /home/vscode/.nix-profile/etc/profile.d/nix.sh \
&& nix-env -i hyperfine wrk rustc cargo go nodejs \
&& nix-env -iA nixpkgs.nodePackages.npm
&& nix-env -iA -f '<nixpkgs>' wrk rustc cargo go nodejs nodePackages.npm dotnet-sdk \
&& ssh-keyscan github.com >> ~/.ssh/known_hosts
1 change: 1 addition & 0 deletions .github/workflows/run.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: crystal-lang/install-crystal@v1
- uses: cachix/install-nix-action@v17
with:
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_modules
bin
main
target
obj
obj
__pycache__
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Benchmarks of the following GraphQL implementations:
* JavaScript: [graphql-jit](https://github.com/zalando-incubator/graphql-jit), [graphql-js](https://github.com/graphql/graphql-js), [graphql-yoga](https://github.com/dotansimha/graphql-yoga)
* Rust: [async-graphql](https://github.com/async-graphql/async-graphql), [Juniper](https://github.com/graphql-rust/juniper)
* .NET: [HotChocolate](https://github.com/ChilliCream/hotchocolate)
* Pyton: [graphene](https://github.com/graphql-python/graphene)

Pull requests welcome.

Expand Down
20 changes: 20 additions & 0 deletions graphene/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import graphene
from flask import Flask
from graphql_server.flask import GraphQLView

class Query(graphene.ObjectType):
hello = graphene.String()
def resolve_hello(self, info):
return 'world'

schema = graphene.Schema(query=Query)

app = Flask(__name__)

app.add_url_rule('/graphql', view_func=GraphQLView.as_view(
'graphql',
schema=schema.graphql_schema,
))

if __name__ == '__main__':
app.run()
5 changes: 5 additions & 0 deletions graphene/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
setuptools
graphene>=3.0
flask
graphql-server
gunicorn
13 changes: 7 additions & 6 deletions run.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,33 @@ require "socket"
b = [
{"async-graphql", "./target/release/async-graphql", nil},
{"gqlgen", "./main", nil},
{"graphene", "gunicorn", ["--log-level", "warning", "-w", System.cpu_count.to_s, "-b", "127.0.0.1:8000", "app:app"]},
{"graphql-crystal", "./main", nil},
{"graphql-jit", "node", ["index.js"]},
{"graphql-js", "node", ["index.js"]},
{"graphql-yoga", "node", ["--no-warnings", "index.js"]},
{"hotchocolate", "dotnet", ["run", "-v", "quiet"]},
{"hotchocolate", "dotnet", ["run", "-v", "quiet", "--nologo"]},
# No usable version of libssl was found
# {"hotchocolate", "./bin/release/net6.0/linux-x64/publish/hotchocolatebench"}
{"juniper", "./target/release/juniper", nil},
]

ch = Channel(Nil).new

b.each do |b|
spawn do
dir = Path[Dir.current, b[0]]

run("shards", ["install", "-q", "--frozen"], dir).wait if File.exists? dir.join("shard.yml")
run("crystal", ["build", "--release", "-D", "preview_mt", "main.cr"], dir).wait if File.exists? dir.join("shard.yml")
run("npm", ["ci", "--silent"], dir).wait if File.exists? dir.join("package.json")
run("cargo", ["build", "--release", "--quiet"], dir).wait if File.exists? dir.join("Cargo.toml")
run("go", ["build", "-o", "main", "main.go"], dir).wait if File.exists? dir.join("go.mod")
run("dotnet", ["publish", "-c", "release", "-r", "linux-x64", "--sc", "-v", "quiet"]).wait if File.exists? dir.join("appsettings.json")
run("dotnet", ["publish", "-c", "release", "-r", "linux-x64", "--sc", "-v", "quiet", "--nologo"], dir).wait if File.exists? dir.join("appsettings.json")
run("pip", ["install", "-q", "-r", "requirements.txt"], dir).wait if File.exists? dir.join("requirements.txt")

ch.send(nil)
end
end

b.each { |b| ch.receive }

b.each do |b|
Expand All @@ -41,13 +43,12 @@ b.each do |b|
while !port_open?
sleep 1
end
if !system("wrk -t#{System.cpu_count} -c#{System.cpu_count * 50} -d30s --timeout 10s --script=post.lua --latency http://127.0.0.1:8000/graphql")
if !system("wrk -t#{System.cpu_count} -c#{System.cpu_count * 50} -d10s --script=post.lua --latency http://127.0.0.1:8000/graphql")
raise "fail"
end
p.terminate
r = p.wait
raise "failed with exit code #{r.exit_code}" if r.exit_code != 0
sleep 2
end

def run(cmd, args = nil, dir = nil)
Expand Down

0 comments on commit 6cbae02

Please sign in to comment.