Skip to content
This repository was archived by the owner on Mar 24, 2026. It is now read-only.

Commit 7f801cd

Browse files
authored
Add dart3 test with for hybrid horizontal scaling with load balancer (#10634)
* revert dart3.dockerfile to scratch * delete run.sh * bump dart version * update HttpStatus for requestTimeout * remove requestTimeout and make _handleRequest synchronous again * remove unnecessary Future and async * move workerGroupTag after pre-existing args * expose args in _startServer function * add base structure for hybrid scaling * fix benchmark_config.json * implement loadbalancer * replace CMD with ENTRYPOINT in Dockerfile * allow --port to be parsed at runtime * update run.sh to make busybox happy * update run.sh to make busybox happy (1) * comments added to run.sh
1 parent 60ad539 commit 7f801cd

8 files changed

Lines changed: 153 additions & 5 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
include: package:lints/recommended.yaml
2+
formatter:
3+
trailing_commas: preserve

frameworks/Dart/dart3/benchmark_config.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@
2424
"language": "Dart",
2525
"os": "Linux",
2626
"database_os": "Linux"
27+
},
28+
"hybrid": {
29+
"display_name": "dart3_hybrid",
30+
"json_url": "/json",
31+
"plaintext_url": "/plaintext",
32+
"port": 8080,
33+
"approach": "Stripped",
34+
"classification": "Platform",
35+
"database": "None",
36+
"language": "Dart",
37+
"os": "Linux",
38+
"database_os": "Linux"
2739
}
28-
}]
40+
}]
2941
}

frameworks/Dart/dart3/bin/server.dart

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:convert';
22
import 'dart:io';
33
import 'dart:isolate';
44
import 'dart:math' show min;
5+
import 'package:args/args.dart' show ArgParser;
56

67
/// Environment declarations are evaluated at compile-time. Use 'const' to
78
/// ensure values are baked into AOT/Native binaries for the benchmark.
@@ -73,7 +74,7 @@ void _startServer(List<String> args) async {
7374
/// Binds the [HttpServer] on `0.0.0.0:8080`.
7475
final server = await HttpServer.bind(
7576
InternetAddress.anyIPv4,
76-
8080,
77+
_portParser(args, defaultPort: 8080),
7778
shared: true,
7879
);
7980

@@ -131,10 +132,28 @@ void _sendText(HttpRequest request, String response) => _sendResponse(
131132
);
132133

133134
/// Responds with the JSON test to the [request].
134-
void _jsonTest(HttpRequest request) =>
135-
_sendJson(request, const {'message': 'Hello, World!'});
135+
void _jsonTest(HttpRequest request) => _sendJson(
136+
request,
137+
const {'message': 'Hello, World!'},
138+
);
136139

137140
/// Responds with the plaintext test to the [request].
138-
void _plaintextTest(HttpRequest request) => _sendText(request, 'Hello, World!');
141+
void _plaintextTest(HttpRequest request) => _sendText(
142+
request,
143+
'Hello, World!',
144+
);
139145

140146
final _jsonEncoder = JsonUtf8Encoder();
147+
148+
int _portParser(
149+
List<String> args, {
150+
required int defaultPort,
151+
portTag = 'port',
152+
}) {
153+
final parser = ArgParser()
154+
..addOption(
155+
portTag,
156+
defaultsTo: '$defaultPort',
157+
);
158+
return int.tryParse(parser.parse(args)[portTag]) ?? defaultPort;
159+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
FROM dart:3.10.8 AS build
3+
WORKDIR /app
4+
5+
# Define the maximum number of Dart Isolates at build time
6+
ARG MAX_ISOLATES=10
7+
8+
COPY pubspec.yaml .
9+
COPY bin bin
10+
11+
RUN dart compile exe bin/server.dart \
12+
--define=MAX_ISOLATES=${MAX_ISOLATES} \
13+
-o server
14+
15+
FROM traefik:latest AS traefik_source
16+
17+
FROM busybox:glibc
18+
WORKDIR /app
19+
# Matches `ARG MAX_ISOLATES` in `build`
20+
ENV MAX_ISOLATES=10
21+
# Define the minimum number of processes dedicated to `Traefik`
22+
ENV MIN_TRAEFIK_PROCESSES=4
23+
24+
COPY --from=build /runtime/ /
25+
COPY --from=build /app/server /app/server
26+
COPY --from=traefik_source /usr/local/bin/traefik /usr/local/bin/traefik
27+
COPY /dart_hybrid/traefik.yaml /etc/traefik/traefik.yaml
28+
COPY /dart_hybrid/traefik_dynamic.yaml /etc/traefik/traefik_dynamic.yaml
29+
COPY /dart_hybrid/run.sh /app/run.sh
30+
31+
RUN chmod +x /app/run.sh
32+
33+
EXPOSE 8080
34+
CMD ["/app/run.sh"]
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/sh
2+
3+
# --- 1. Environment & Hardware Detection ---
4+
TOTAL_PROCESSES=$(grep -c ^processor /proc/cpuinfo)
5+
MAX_ISO=${MAX_ISOLATES:-8}
6+
RESERVED=${MIN_TRAEFIK_PROCESSES:-4}
7+
8+
# --- 2. Scaling Logic ---
9+
if [ "$TOTAL_PROCESSES" -le "$((MAX_ISO * 2))" ]; then
10+
exec /app/server
11+
else
12+
DART_POOL=$((TOTAL_PROCESSES - RESERVED))
13+
NUM_WORKERS=$(( DART_POOL / MAX_ISO ))
14+
DART_PROCESSES=$(( NUM_WORKERS * MAX_ISO ))
15+
TRAEFIK_PROCESSES=$(( TOTAL_PROCESSES - DART_PROCESSES ))
16+
17+
export GOMAXPROCS=$TRAEFIK_PROCESSES
18+
19+
# --- 3. Generate Backend List ---
20+
TMP_URLS="/tmp/urls.yaml"
21+
true > "$TMP_URLS"
22+
23+
for i in $(seq 1 $NUM_WORKERS); do
24+
PORT=$((9000 + i))
25+
echo " - url: \"http://127.0.0.1:$PORT\"" >> "$TMP_URLS"
26+
27+
/app/server --port=$PORT &
28+
done
29+
30+
# --- 4. Traefik Configuration ---
31+
sed -i "/# DART_WORKERS_PLACEHOLDER/ {
32+
r $TMP_URLS
33+
d
34+
}" /etc/traefik/traefik_dynamic.yaml
35+
rm "$TMP_URLS"
36+
37+
# --- 5. Readiness & Execution ---
38+
until nc -z 127.0.0.1 9001; do sleep 0.1; done
39+
40+
exec traefik --configfile=/etc/traefik/traefik.yaml
41+
fi
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
global:
2+
checkNewVersion: false
3+
sendAnonymousUsage: false
4+
5+
entryPoints:
6+
web:
7+
address: ":8080"
8+
transport:
9+
respondingTimeouts:
10+
readTimeout: "0s"
11+
writeTimeout: "0s"
12+
idleTimeout: "0s"
13+
14+
providers:
15+
file:
16+
filename: /etc/traefik/traefik_dynamic.yaml
17+
watch: false
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
http:
2+
routers:
3+
to-dart:
4+
rule: "PathPrefix(`/`)"
5+
service: dart-service
6+
middlewares:
7+
- dart-header
8+
entryPoints:
9+
- web
10+
middlewares:
11+
dart-header:
12+
headers:
13+
customResponseHeaders:
14+
Server: "dart"
15+
services:
16+
dart-service:
17+
loadBalancer:
18+
servers:
19+
# DART_WORKERS_PLACEHOLDER

frameworks/Dart/dart3/pubspec.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@ description: A benchmark of dart
33
environment:
44
sdk: ^3.10.8
55

6+
dependencies:
7+
args: ^2.7.0
8+
69
dev_dependencies:
710
lints: ^6.0.0
11+

0 commit comments

Comments
 (0)