Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jaguililla committed Aug 15, 2024
2 parents b05b433 + b669efd commit f7526b5
Show file tree
Hide file tree
Showing 130 changed files with 1,476 additions and 1,056 deletions.
2 changes: 1 addition & 1 deletion frameworks/C/h2o/h2o.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ RUN apt-get -yqq update && \
ruby \
systemtap-sdt-dev

ARG H2O_VERSION=18b175f71ede08b50d3e5ae8303dacef3ea510fc
ARG H2O_VERSION=c54c63285b52421da2782f028022647fc2ea3dd1

WORKDIR /tmp/h2o-build
RUN curl -LSs "https://github.com/h2o/h2o/archive/${H2O_VERSION}.tar.gz" | \
Expand Down
6 changes: 4 additions & 2 deletions frameworks/C/h2o/src/handlers/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ static int do_multiple_queries(bool do_update, bool use_cache, h2o_req_t *req)
const size_t num_query = get_query_number(req);

// MAX_QUERIES is a relatively small number, say less than or equal to UINT16_MAX, so assume no
// overflow in the following arithmetic operations.
assert(num_query && num_query <= MAX_QUERIES && num_query <= UINT16_MAX);
// unsigned overflow in the following arithmetic operations.
static_assert(MAX_QUERIES <= UINT16_MAX,
"potential out-of-bounds memory accesses in the following code");
assert(num_query && num_query <= MAX_QUERIES);

size_t base_size = offsetof(multiple_query_ctx_t, res) + num_query * sizeof(query_result_t);

Expand Down
9 changes: 9 additions & 0 deletions frameworks/Dart/dart3/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# From https://hub.docker.com/_/dart
.dockerignore
Dockerfile
build/
.dart_tool/
.git/
.github/
.gitignore
.packages
5 changes: 5 additions & 0 deletions frameworks/Dart/dart3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
*.lock
!bin
22 changes: 22 additions & 0 deletions frameworks/Dart/dart3/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Dart 3 Benchmarking Test

### Test Type Implementation Source Code

- [JSON](server.dart)
- [PLAINTEXT](server.dart)

## Important Libraries

The tests were run with:

- [Dart v3.4.4](https://dart.dev/)

## Test URLs

### JSON

http://localhost:8080/json

### PLAINTEXT

http://localhost:8080/plaintext
1 change: 1 addition & 0 deletions frameworks/Dart/dart3/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/recommended.yaml
26 changes: 26 additions & 0 deletions frameworks/Dart/dart3/benchmark_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"framework": "dart3",
"tests": [
{
"default": {
"json_url": "/json",
"plaintext_url": "/plaintext",
"port": 8080,
"approach": "Stripped",
"classification": "Platform",
"database": "None",
"framework": "None",
"language": "Dart",
"flavor": "None",
"orm": "None",
"platform": "None",
"webserver": "None",
"os": "Linux",
"database_os": "Linux",
"display_name": "dart3",
"notes": "",
"versus": "None"
}
}
]
}
89 changes: 89 additions & 0 deletions frameworks/Dart/dart3/bin/server.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'dart:convert';
import 'dart:io';
import 'dart:isolate';

final _encoder = JsonUtf8Encoder();

void main(List<String> _) async {
/// Create an [Isolate] containinig an [HttpServer]
/// for each processor after the first
for (var i = 1; i < Platform.numberOfProcessors; i++) {
await Isolate.spawn(_startServer, _);
}

/// Create a [HttpServer] for the first processor
await _startServer(_);
}

/// Creates and setup a [HttpServer]
Future<void> _startServer(List<String> _) async {
/// Binds the [HttpServer] on `0.0.0.0:8080`.
final server = await HttpServer.bind(
InternetAddress('0.0.0.0', type: InternetAddressType.IPv4),
8080,
shared: true,
);

/// Sets [HttpServer]'s [serverHeader].
server
..defaultResponseHeaders.clear()
..serverHeader = 'dart';

/// Handles [HttpRequest]'s from [HttpServer].
await for (final request in server) {
switch (request.uri.path) {
case '/json':
_jsonTest(request);
break;
case '/plaintext':
_plaintextTest(request);
break;
default:
_sendResponse(request, HttpStatus.notFound);
}
}
}

/// Completes the given [request] by writing the [bytes] with the given
/// [statusCode] and [type].
void _sendResponse(
HttpRequest request,
int statusCode, {
ContentType? type,
List<int> bytes = const [],
}) =>
request.response
..statusCode = statusCode
..headers.contentType = type
..headers.date = DateTime.now()
..contentLength = bytes.length
..add(bytes)
..close();

/// Completes the given [request] by writing the [response] as JSON.
void _sendJson(HttpRequest request, Object response) => _sendResponse(
request,
HttpStatus.ok,
type: ContentType.json,
bytes: _encoder.convert(response),
);

/// Completes the given [request] by writing the [response] as plain text.
void _sendText(HttpRequest request, String response) => _sendResponse(
request,
HttpStatus.ok,
type: ContentType.text,
bytes: utf8.encode(response),
);

/// Responds with the JSON test to the [request].
void _jsonTest(HttpRequest request) => _sendJson(
request,
const {'message': 'Hello, World!'},
);

/// Responds with the plaintext test to the [request].
void _plaintextTest(HttpRequest request) => _sendText(
request,
'Hello, World!',
);
14 changes: 14 additions & 0 deletions frameworks/Dart/dart3/dart3.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

FROM dart:3.5 AS builder

COPY . /app
WORKDIR /app
RUN mkdir build
RUN dart compile exe ./bin/server.dart -o build/server

FROM scratch
COPY --from=builder /runtime/ /
COPY --from=builder /app/build /bin

EXPOSE 8080
CMD ["server"]
7 changes: 7 additions & 0 deletions frameworks/Dart/dart3/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: dartbenchmark
description: A benchmark of dart
environment:
sdk: '>=3.5.0 <4.0.0'

dev_dependencies:
lints: ^4.0.0
29 changes: 2 additions & 27 deletions frameworks/Elixir/phoenix/benchmark_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,6 @@
"framework": "phoenix",
"tests": [{
"default": {
"json_url": "/json",
"db_url": "/db",
"query_url": "/queries?queries=",
"fortune_url": "/fortunes",
"plaintext_url": "/plaintext",
"update_url": "/updates?queries=",
"cached_query_url": "/cached-queries?count=",
"port": 8080,
"approach": "Realistic",
"classification": "Fullstack",
"database": "Postgres",
"framework": "Phoenix",
"language": "Elixir",
"flavor": "None",
"orm": "full",
"platform": "beam",
"webserver": "cowboy",
"os": "Linux",
"database_os": "Linux",
"display_name": "Phoenix",
"notes": "",
"versus": ""
},
"bandit": {
"json_url": "/json",
"db_url": "/db",
"query_url": "/queries?queries=",
Expand All @@ -45,9 +21,8 @@
"webserver": "bandit",
"os": "Linux",
"database_os": "Linux",
"display_name": "Phoenix-Bandit",
"notes": "",
"versus": "default"
"display_name": "Phoenix",
"notes": ""
}
}]
}
43 changes: 0 additions & 43 deletions frameworks/Elixir/phoenix/config/bandit.exs

This file was deleted.

8 changes: 8 additions & 0 deletions frameworks/Elixir/phoenix/config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ config :hello, HelloWeb.Endpoint,
debug_errors: false,
secret_key_base: "Z18ZjzZslFpKd8HB41IljqMavPiOKVF9y1DIQ+S2Ytg7Op0EIauwJgd7mtRStssx"

# Configure cache for world entities
config :hello, Hello.WorldCache,
gc_interval: :timer.hours(1),
max_size: 1_000_000,
allocated_memory: 100_000_000,
gc_cleanup_min_timeout: :timer.seconds(30),
gc_cleanup_max_timeout: :timer.minutes(30)

# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
Expand Down
9 changes: 5 additions & 4 deletions frameworks/Elixir/phoenix/config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Config

config :hello, HelloWeb.Endpoint,
url: [host: "0.0.0.0"],
http: [port: 8080, protocol_options: [max_keepalive: :infinity], backlog: 8096],
cache_static_lookup: false,
adapter: Bandit.PhoenixAdapter,
http: [port: 8080, ip: {0, 0, 0, 0}],
http_options: [log_protocol_errors: false],
compress: false,
check_origin: false,
debug_errors: false,
code_reloader: false,
Expand All @@ -14,7 +15,7 @@ config :hello, Hello.Repo,
password: "benchmarkdbpass",
database: "hello_world",
hostname: "tfb-database",
pool_size: 40,
pool_size: 50,
queue_target: 5000,
log: false

Expand Down
2 changes: 1 addition & 1 deletion frameworks/Elixir/phoenix/lib/hello/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Hello.Application do
def start(_type, _args) do
children = [
Hello.Repo,
{Hello.Cache, []},
{Hello.WorldCache, []},
HelloWeb.Endpoint
]

Expand Down
5 changes: 0 additions & 5 deletions frameworks/Elixir/phoenix/lib/hello/cache.ex

This file was deleted.

31 changes: 31 additions & 0 deletions frameworks/Elixir/phoenix/lib/hello/world_cache.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
defmodule Hello.WorldCache do
use Nebulex.Cache,
otp_app: :hello,
adapter: Nebulex.Adapters.Local

alias Hello.Models.World
alias Hello.Repo

def seed do
if not __MODULE__.has_key?(:seeded) do
World
|> Repo.all()
|> Enum.into([], &{&1.id, &1})
|> __MODULE__.put_all()

__MODULE__.put(:seeded, true)
end
end

def fetch(id) do
case __MODULE__.get(id) do
nil ->
world = Repo.get(World, id)
:ok = __MODULE__.put(id, world)
world
world ->
world
end
end

end
4 changes: 1 addition & 3 deletions frameworks/Elixir/phoenix/lib/hello_web.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ defmodule HelloWeb do
defp html_helpers do
quote do
# Use all HTML functionality (forms, tags, etc)
use Phoenix.HTML
# Core UI Components and translation
import HelloWeb.Gettext
import Phoenix.HTML

# Routes generation with the ~p sigil
unquote(verified_routes())
Expand Down
Loading

0 comments on commit f7526b5

Please sign in to comment.