Skip to content

Fb/add hc to benchmarks #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ logs
*.log
npm-debug.log*

obj/
bin/

# Runtime data
pids
*.pid
Expand Down Expand Up @@ -60,4 +63,4 @@ results

dist
results100
results5
results5
4 changes: 2 additions & 2 deletions benchmark-bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ inquirer
type: "input",
name: "connections",
message: "How many connections do you need?",
default: 5,
default: 10,
validate(value) {
return !Number.isNaN(parseFloat(value)) || "Please enter a number";
},
Expand All @@ -58,7 +58,7 @@ inquirer
type: "input",
name: "duration",
message: "How long should it take?",
default: 5,
default: 20,
validate(value) {
return !Number.isNaN(parseFloat(value)) || "Please enter a number";
},
Expand Down
12 changes: 12 additions & 0 deletions benchmarks/HotChocolateServer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

const { join } = require("path");
var hcDir = join(__dirname, "HotChocolateServer/HotChocolateServer.csproj");

var dotnetProcess = require('child_process').spawn('dotnet run -c Release --project ' + hcDir, [], {
shell: true,
detached: true
});

process.on('SIGINT', function () {
process.kill(-dotnetProcess.pid)
});
30 changes: 30 additions & 0 deletions benchmarks/HotChocolateServer/Data/AuthorRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.IO;
using System.Reflection;
using System.Text.Json;
using HotChocolateServer.Schema;

namespace HotChocolateServer.Data
{
public class AuthorRepository
{
public Author[] Authors { get; set; }

public AuthorRepository()
{
var jsonData = string.Empty;
var resourceName = this.GetType().Namespace + ".data.json";

using (Stream? stm = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)) {
if (stm != null) {
jsonData = new StreamReader(stm).ReadToEnd();
}
}

Authors = JsonSerializer.Deserialize<Author[]>(jsonData, new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true
}) ?? throw new ArgumentNullException();
}
}
}
1 change: 1 addition & 0 deletions benchmarks/HotChocolateServer/Data/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"id":"e64b985f-4a35-491e-9081-21a4d4635628","name":"Alanis Bailey","company":"synergistic redefine methodologies","books":[{"id":"12dbc24c-3cfc-46dc-a164-0977434afabf","name":"stefan.biz","numPages":72722},{"id":"92656ef1-e1f5-4685-baf0-9346611c0d62","name":"adah.com","numPages":12714},{"id":"4402d193-e07f-46a3-b915-27abfcff23b9","name":"russell.com","numPages":29061}]},{"id":"78f71319-85f7-469d-9311-2895dbf76535","name":"Grayce Johns","company":"24/7 embrace communities","books":[{"id":"a3f7b528-33f4-4898-ae33-04dca1c227e2","name":"orland.biz","numPages":66593},{"id":"a2586a95-ce1f-421b-b4a0-2b7c79f4a497","name":"kendall.name","numPages":68775},{"id":"a5cbedb2-73b6-401b-a11c-91136bca8675","name":"elmore.net","numPages":79213}]},{"id":"864c1956-b77f-46cb-96ec-f7411e5190c4","name":"Delores Graham","company":"end-to-end revolutionize experiences","books":[{"id":"fa12d3f6-4368-42c2-8a1d-65e9761dc2dd","name":"ricardo.name","numPages":79872},{"id":"d509ce52-990c-4f84-b165-58e68e9a4675","name":"tito.net","numPages":94169},{"id":"00691a2b-b1db-47ca-af4f-f9ec563ea71c","name":"monte.info","numPages":97610}]},{"id":"5f27e1ee-c6d0-4a94-b322-d7fc5938ebff","name":"Vernie Quigley","company":"proactive deploy solutions","books":[{"id":"b50a3c7b-ab03-4458-9026-fb3d06cb3780","name":"richmond.name","numPages":12839},{"id":"b17b4749-a3f6-49c8-bfb7-a0abb555f2b6","name":"ruben.name","numPages":4081},{"id":"65d71220-df12-42e6-b2ba-88a5d5084350","name":"monty.net","numPages":65899}]},{"id":"491b33fd-182c-4f0b-90d4-f2f929bbb6d9","name":"Lisa Collins","company":"plug-and-play implement portals","books":[{"id":"a09a0672-f017-45df-8625-0f245536017d","name":"deangelo.info","numPages":50695},{"id":"2b943a25-1ee4-4358-a308-cb4a71b11a43","name":"royal.net","numPages":99654},{"id":"497b8522-850d-44de-9061-cf1b472066bf","name":"domingo.net","numPages":15604}]},{"id":"da0386ae-5b46-4b75-858f-5a31272352d5","name":"Nick Rau","company":"e-business extend synergies","books":[{"id":"d83ab58b-33b8-4962-9414-11ee62c0b200","name":"noemy.info","numPages":72298},{"id":"43110c3f-4793-4701-83de-d86917767f50","name":"matilda.name","numPages":45419},{"id":"5ed1c0ed-7d1e-4fc8-a131-558a4136b1c5","name":"sheridan.com","numPages":3703}]},{"id":"2aad5e23-02a6-4834-9332-510afae6eab0","name":"Joana Lynch","company":"bleeding-edge orchestrate architectures","books":[{"id":"1d40d9dd-25ae-435d-b92b-9b7442d9140a","name":"alisha.info","numPages":89078},{"id":"ece711da-c858-4068-95c9-ffe84ac5518a","name":"eliseo.info","numPages":50538},{"id":"32ddcaca-a4e0-4e46-92ee-9f5ef7f1b7d7","name":"tre.com","numPages":48820}]},{"id":"f3819414-206d-4611-b0cb-707c399210da","name":"Amparo Lowe","company":"sticky incentivize experiences","books":[{"id":"42fe82d5-04f2-4f05-8825-2858cc89a467","name":"stacy.name","numPages":43639},{"id":"8281b015-d958-430a-b12e-b1b7767fe7dc","name":"saul.biz","numPages":86083},{"id":"505cfc43-92bb-43e8-b050-653b5afba5e9","name":"ethelyn.org","numPages":91179}]},{"id":"4403f645-c2e3-4f8d-9027-127dca09f353","name":"Guy Rath DDS","company":"robust strategize systems","books":[{"id":"c6d6aa58-c492-45a6-b23f-aa78c68e36e3","name":"bridie.biz","numPages":17490},{"id":"45e897e0-74c8-4188-acfb-0e3416099909","name":"nya.info","numPages":59110},{"id":"5e7c5e3c-b029-4424-bf41-847025997de7","name":"turner.net","numPages":58080}]},{"id":"bbbc1065-17e0-4260-b085-a5ff17a2d792","name":"Gerard Murphy","company":"intuitive redefine paradigms","books":[{"id":"781a3052-f535-4bda-8794-95dbdd9b6230","name":"cindy.info","numPages":72375},{"id":"1743d911-b325-4b2b-97fc-0fa9ba6ba1b9","name":"alfred.biz","numPages":757},{"id":"a55ccafc-743c-4142-8707-94a6ff9ba9ff","name":"scotty.com","numPages":38367}]},{"id":"6fab7bbd-3567-4dfc-bb9b-93115a6e667f","name":"Madaline Price","company":"one-to-one streamline metrics","books":[{"id":"6c9cfc8d-475c-40d6-9139-401093c57ce5","name":"tina.org","numPages":86813},{"id":"191a0ced-5240-43a9-85b9-fc4577834eac","name":"anne.biz","numPages":7562},{"id":"44405a01-cac5-45ec-9c9f-d06b97fdbe36","name":"maximo.net","numPages":80960}]},{"id":"d8b7eb93-54b0-4f5c-9bcf-88b39f453e97","name":"Clotilde Wuckert","company":"efficient deliver partnerships","books":[{"id":"bb03f796-0b36-4e67-8046-b6c23e1f9615","name":"adolph.biz","numPages":48674},{"id":"1524b0f8-cec3-4188-a280-7352003a9db7","name":"gilbert.com","numPages":33955},{"id":"b35be6dd-8bcf-416c-bc26-c396133898d3","name":"loyal.info","numPages":86006}]},{"id":"2996bf9a-1c0a-4abf-862d-b8ea8218a3fe","name":"Dayana Gaylord","company":"impactful enhance ROI","books":[{"id":"0bdbc8df-324f-4c42-819a-33e874c4fa5c","name":"gladyce.org","numPages":27761},{"id":"50f0778f-fa09-47e9-857f-266f75661e83","name":"paris.net","numPages":57051},{"id":"aac19c76-fb82-4ffc-ad34-61540b8193fc","name":"ima.net","numPages":13111}]},{"id":"73d7087a-6a67-406e-8070-8d53e8134e06","name":"Rene Kozey","company":"robust synthesize e-business","books":[{"id":"acc0910d-c6ea-40e3-b0bd-fa30c1bc82ca","name":"nelle.org","numPages":68394},{"id":"ac24e7ec-ba82-46a1-9cfe-50797169d1e9","name":"harmon.com","numPages":27420},{"id":"bed5623b-6466-47da-9cd2-21b51d5ee661","name":"sammy.org","numPages":20763}]},{"id":"78ccf92c-1200-41df-ac96-7832946042d1","name":"Ms. Judah Dickinson","company":"out-of-the-box generate web-readiness","books":[{"id":"95cea36c-8b30-457b-9ae6-8ebb92c13274","name":"emory.name","numPages":80950},{"id":"4d742b70-9176-4f4b-bcbb-b42fe29b106d","name":"andres.name","numPages":12698},{"id":"018a9651-740c-49c0-9a01-e27457d1bd4f","name":"gonzalo.net","numPages":2012}]},{"id":"b03cc48e-19d1-49b5-9c8f-aa78ee1c98d3","name":"Kieran Langosh","company":"bricks-and-clicks cultivate schemas","books":[{"id":"219e159b-9c18-4f2e-9f2c-334624265bac","name":"kimberly.com","numPages":66230},{"id":"300a1d45-ea4b-4d0d-abca-903776836bef","name":"gunner.name","numPages":39973},{"id":"b46f59d6-5691-4acf-847c-544b1b494f9b","name":"saige.name","numPages":40011}]},{"id":"3080c2b2-512b-4db0-8ed7-f466b341a7c4","name":"Dr. Jerod Stamm","company":"front-end streamline web services","books":[{"id":"32d76464-e0d1-43cb-b9d1-0ff7992dc86c","name":"kaylah.name","numPages":62799},{"id":"1c5f67b5-ebd6-4833-a02c-7ae80c87bb77","name":"myrna.com","numPages":17237},{"id":"abf1bc0a-8374-486d-837c-86ac89503880","name":"ardith.name","numPages":15576}]},{"id":"e4319465-1bfe-406f-83f7-3d08b926cafc","name":"Cierra Fisher","company":"wireless iterate supply-chains","books":[{"id":"abc41bfb-d37f-4004-9ede-6d6180286ae0","name":"elnora.net","numPages":84294},{"id":"bac62bce-0b4b-406f-913b-3664540b3602","name":"dion.info","numPages":39400},{"id":"8a6a0563-fc96-4775-9bf3-b88d4b7bf2e4","name":"daren.name","numPages":55580}]},{"id":"839faacd-c6bd-475c-b973-9f898a95a21c","name":"Baron Ratke","company":"granular synergize synergies","books":[{"id":"cb599437-a054-4b8f-bdb4-c62e20091f94","name":"manuel.org","numPages":65627},{"id":"47571d03-8350-4da4-9f2f-9cecddd13063","name":"jeramy.com","numPages":28276},{"id":"0be94899-e49c-4206-a0c8-ab01c28a8ca7","name":"nico.net","numPages":78426}]},{"id":"eced005c-74cb-4e27-bf6a-0662d4ff386a","name":"Lennie Cassin","company":"out-of-the-box engineer schemas","books":[{"id":"5deb43f8-d566-4dbf-90dc-558b632588da","name":"bridget.net","numPages":600},{"id":"2b81f21f-3a32-4e04-9eb8-ccd8254d7654","name":"nolan.net","numPages":10760},{"id":"0314a63d-ee76-4f74-98f2-67d4676bc892","name":"ashleigh.net","numPages":47238}]}]
21 changes: 21 additions & 0 deletions benchmarks/HotChocolateServer/HotChocolateServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<Nullable>Enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="HotChocolate.AspNetCore" Version="11.0.0-rc.8" />
</ItemGroup>

<ItemGroup>
<Content Remove="Data\data.json" />
<EmbeddedResource Include="Data\data.json">
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</EmbeddedResource>
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions benchmarks/HotChocolateServer/HotChocolateServer.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotChocolateServer", "HotChocolateServer.csproj", "{4B1ECFD7-98D6-4282-B7D9-1DD7820214C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B1ECFD7-98D6-4282-B7D9-1DD7820214C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4B1ECFD7-98D6-4282-B7D9-1DD7820214C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4B1ECFD7-98D6-4282-B7D9-1DD7820214C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4B1ECFD7-98D6-4282-B7D9-1DD7820214C2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
17 changes: 17 additions & 0 deletions benchmarks/HotChocolateServer/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace HotChocolateServer
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
29 changes: 29 additions & 0 deletions benchmarks/HotChocolateServer/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:61509",
"sslPort": 44377
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
"HotChocolateServer": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": false,
"applicationUrl": "http://localhost:4001",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
}
}
}
10 changes: 10 additions & 0 deletions benchmarks/HotChocolateServer/Schema/Author.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HotChocolateServer.Schema
{
public class Author
{
public string Id { get; set; }
public string Name { get; set; }
public string Company { get; set; }
public Book[] Books { get; set; }
}
}
9 changes: 9 additions & 0 deletions benchmarks/HotChocolateServer/Schema/Book.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace HotChocolateServer.Schema
{
public class Book
{
public string Id { get; set; }
public string Name { get; set; }
public int Pages { get; set; }
}
}
13 changes: 13 additions & 0 deletions benchmarks/HotChocolateServer/Schema/Query.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using HotChocolate;
using HotChocolateServer.Data;

namespace HotChocolateServer.Schema
{
public class Query
{
public Author[] GetAuthors([Service] AuthorRepository authorRepository)
{
return authorRepository.Authors;
}
}
}
44 changes: 44 additions & 0 deletions benchmarks/HotChocolateServer/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using HotChocolateServer.Data;
using HotChocolateServer.Schema;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace HotChocolateServer
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) =>
services
.AddSingleton<AuthorRepository>()
.AddGraphQLServer()
.AddQueryType<Query>();

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseRouting();

app.UseEndpoints(
endpoints =>
{
endpoints.MapGraphQL();
});
}
}
}
7 changes: 7 additions & 0 deletions benchmarks/HotChocolateServer/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
}
}
5 changes: 5 additions & 0 deletions benchmarks/HotChocolateServer/global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "5.0.100"
}
}
2 changes: 1 addition & 1 deletion lib/autocannon.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const resultsDirectory = path.join(process.cwd(), "results");

const body = JSON.stringify({
query:
"{\n authors {\n id\n name\n md5\n books {\n id\n name\n }\n }\n}"
"{\n authors {\n id\n name\n books {\n id\n name\n }\n }\n}"
});

const run = (opts = {}) =>
Expand Down
2 changes: 1 addition & 1 deletion lib/choices.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ const { join } = require("path");

module.exports.choices = readdirSync(
join(__dirname, "..", "benchmarks")
).map(x => x.replace(".js", ""));
).filter(x => x.endsWith(".js")).map(x => x.replace(".js", ""));
4 changes: 4 additions & 0 deletions lib/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function genData() {
});
}

const fs = require('fs');
let data = JSON.stringify(authors);
fs.writeFileSync('./benchmarks/HotChocolateServer/Data/data.json', data);

return authors;
}

Expand Down
7 changes: 0 additions & 7 deletions lib/schemas/createApolloSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const typeDefs = gql`
type Author {
id: ID!
name: String!
md5: String!
company: String!
books: [Book!]!
}
Expand All @@ -24,9 +23,6 @@ const typeDefs = gql`
`;

const resolvers = {
Author: {
md5: parent => md5(parent.name)
},
Query: {
authors: () => {
return data;
Expand All @@ -35,9 +31,6 @@ const resolvers = {
};

const asyncResolvers = {
Author: {
md5: parent => md5(parent.name)
},
Query: {
authors: async () => {
return data;
Expand Down
4 changes: 0 additions & 4 deletions lib/schemas/createGraphqlCompose.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ sc.createObjectTC({
fields: {
id: 'ID!',
name: 'String!',
md5: {
type: 'String!',
resolve: parent => md5(parent.name)
},
company: 'String!',
books: '[Book!]!'
}
Expand Down
4 changes: 0 additions & 4 deletions lib/schemas/createTypeGraphQLSchema.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 0 additions & 16 deletions lib/schemas/createTypeGraphQLSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class Author {

@Resolver(Author)
class SimpleResolver {
@FieldResolver()
md5(@Root() root: Author) {
return md5(root.name);
}
@Query(() => [Author])
authors() {
return data;
Expand All @@ -52,10 +48,6 @@ class SimpleResolver {

@Resolver(Author)
class AsyncResolver {
@FieldResolver()
md5(@Root() root: Author) {
return md5(root.name);
}
@Query(() => [Author])
async authors() {
return data;
Expand All @@ -64,10 +56,6 @@ class AsyncResolver {

@Resolver(Author)
class MiddlewareResolver {
@FieldResolver()
md5(@Root() root: Author) {
return md5(root.name);
}
@Query(() => [Author])
@UseMiddleware(({ args }, next) => {
Object.keys(args).length;
Expand All @@ -80,10 +68,6 @@ class MiddlewareResolver {

@Resolver(Author)
class AsyncMiddlewareResolver {
@FieldResolver()
md5(@Root() root: Author) {
return md5(root.name);
}
@Query(() => [Author])
@UseMiddleware(async ({ args }, next) => {
Object.keys(args).length;
Expand Down
Loading