Skip to content

Commit 2801d3d

Browse files
authored
feat: Add Relic framework. (#10155)
1 parent 4580dcc commit 2801d3d

File tree

7 files changed

+154
-0
lines changed

7 files changed

+154
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# From https://hub.docker.com/_/dart
2+
.dockerignore
3+
Dockerfile
4+
build/
5+
.dart_tool/
6+
.git/
7+
.github/
8+
.gitignore
9+
.packages

frameworks/Dart/relic/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# https://dart.dev/guides/libraries/private-files
2+
# Created by `dart pub`
3+
.dart_tool/
4+
*.lock
5+
!bin

frameworks/Dart/relic/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Relic Benchmarking Test
2+
3+
### Test Type Implementation Source Code
4+
5+
- [JSON](server.dart)
6+
- [PLAINTEXT](server.dart)
7+
8+
## Important Libraries
9+
10+
The tests were run with:
11+
12+
- [pkg:relic](https://pub.dev/packages/relic)
13+
- [Dart](https://dart.dev/)
14+
15+
## Test URLs
16+
17+
### JSON
18+
19+
http://localhost:8080/json
20+
21+
### PLAINTEXT
22+
23+
http://localhost:8080/plaintext
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"framework": "relic",
3+
"tests": [
4+
{
5+
"default": {
6+
"json_url": "/json",
7+
"plaintext_url": "/plaintext",
8+
"port": 8080,
9+
"approach": "Realistic",
10+
"classification": "Micro",
11+
"database": "None",
12+
"framework": "relic",
13+
"language": "Dart",
14+
"flavor": "None",
15+
"orm": "None",
16+
"platform": "relic",
17+
"webserver": "None",
18+
"os": "Linux",
19+
"database_os": "Linux",
20+
"display_name": "relic",
21+
"notes": "",
22+
"versus": "None"
23+
}
24+
}
25+
]
26+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import 'dart:convert';
2+
import 'dart:io';
3+
import 'dart:isolate';
4+
import 'dart:typed_data';
5+
6+
import 'package:relic/io_adapter.dart';
7+
import 'package:relic/relic.dart';
8+
9+
void main() async {
10+
/// Number of [Isolate]s to spawn
11+
/// This is based on the number of available processors
12+
/// minus one for the main isolate
13+
final isolateCount = Platform.numberOfProcessors * 2 - 1;
14+
15+
/// Create an [Isolate] containing an [HttpServer]
16+
await Future.wait(
17+
List.generate(
18+
isolateCount,
19+
(final index) =>
20+
Isolate.spawn((final _) => _serve(), null, debugName: '$index'),
21+
),
22+
);
23+
24+
_serve();
25+
}
26+
27+
/// [_serve] is called in each spawned isolate.
28+
Future<void> _serve() async {
29+
final router = Router<Handler>()
30+
..get('/json', respondWith((req) => _responseJson()))
31+
..get('/plaintext', respondWith((req) => _responsePlainText()));
32+
33+
final handler = const Pipeline()
34+
.addMiddleware(_requiredHeadersMiddleware())
35+
.addMiddleware(routeWith(router))
36+
.addHandler(respondWith((_) => Response.notFound()));
37+
38+
// start the server
39+
await serve(handler, InternetAddress.anyIPv4, 8080, shared: true);
40+
}
41+
42+
Middleware _requiredHeadersMiddleware() {
43+
var addHeaders = createMiddleware(
44+
onResponse: (response) => response.copyWith(
45+
headers: response.headers.transform((headers) {
46+
headers.server = 'relic';
47+
// Date header is added by default, but we set it here for clarity.
48+
headers.date = DateTime.now();
49+
}),
50+
),
51+
);
52+
return addHeaders;
53+
}
54+
55+
Response _responseJson() {
56+
return Response.ok(
57+
body: Body.fromData(
58+
_jsonEncoder.convert(const {'message': 'Hello, World!'}) as Uint8List,
59+
mimeType: MimeType.json,
60+
),
61+
);
62+
}
63+
64+
Response _responsePlainText() {
65+
return Response.ok(
66+
body: Body.fromString('Hello, World!', mimeType: MimeType.plainText),
67+
);
68+
}
69+
70+
final _jsonEncoder = JsonUtf8Encoder();

frameworks/Dart/relic/pubspec.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
name: relicbenchmark
2+
description: A benchmark of pkg:relic
3+
environment:
4+
sdk: ^3.8.0
5+
6+
dependencies:
7+
relic: ^0.7.0
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
FROM dart:3.9 AS builder
3+
4+
COPY . /app
5+
WORKDIR /app
6+
RUN mkdir build
7+
RUN dart compile exe ./bin/server.dart -o build/server
8+
9+
FROM scratch
10+
COPY --from=builder /runtime/ /
11+
COPY --from=builder /app/build /bin
12+
13+
EXPOSE 8080
14+
CMD ["server"]

0 commit comments

Comments
 (0)