Skip to content

Commit f8bb37d

Browse files
authored
Dart3 update (#10493)
* add logic for variable --define=MAX_ISOLATES * add run.sh and optimize scaling logic in Dockerfile * bump dart and dependencies version everywhere
1 parent 6066c32 commit f8bb37d

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

frameworks/Dart/dart3/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dart 3 Benchmarking Test
22

3-
### Test Type Implementation Source Code
3+
## Test Type Implementation Source Code
44

55
- [JSON](server.dart)
66
- [PLAINTEXT](server.dart)
@@ -9,14 +9,14 @@
99

1010
The tests were run with:
1111

12-
- [Dart v3.4.4](https://dart.dev/)
12+
- [Dart v3.10.7](https://dart.dev/)
1313

1414
## Test URLs
1515

1616
### JSON
1717

18-
http://localhost:8080/json
18+
`http://localhost:8080/json`
1919

2020
### PLAINTEXT
2121

22-
http://localhost:8080/plaintext
22+
`http://localhost:8080/plaintext`

frameworks/Dart/dart3/bin/server.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,17 @@ import 'dart:io';
33
import 'dart:isolate';
44

55
void main(List<String> args) async {
6+
/// Isolate count per process, set at build-time via:
7+
/// dart compile exe --define=MAX_ISOLATES=X
8+
/// Defaults to machine core count for dynamic scaling.
9+
final maxIsolates = int.fromEnvironment(
10+
'MAX_ISOLATES',
11+
defaultValue: Platform.numberOfProcessors,
12+
);
13+
614
/// Create an [Isolate] containing an [HttpServer]
715
/// for each processor after the first
8-
for (var i = 1; i < Platform.numberOfProcessors; i++) {
16+
for (var i = 1; i < maxIsolates; i++) {
917
await Isolate.spawn(_startServer, args);
1018
}
1119

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11

2-
FROM dart:3.8 AS builder
3-
4-
COPY . /app
2+
FROM dart:3.10.7 AS builder
53
WORKDIR /app
4+
5+
# Define the build-time argument (Default to 8)
6+
ARG MAX_ISOLATES=8
7+
COPY . .
68
RUN mkdir build
7-
RUN dart compile exe ./bin/server.dart -o build/server
9+
RUN dart compile exe bin/server.dart \
10+
--define=MAX_ISOLATES=${MAX_ISOLATES} \
11+
-o build/server
12+
13+
FROM busybox:glibc
14+
15+
# Re-declare ARG in the second stage to use it in ENV
16+
# Define the build-time argument (Default to 8)
17+
ARG MAX_ISOLATES=8
18+
ENV MAX_ISOLATES_PER_PROCESS=${MAX_ISOLATES}
819

9-
FROM scratch
1020
COPY --from=builder /runtime/ /
11-
COPY --from=builder /app/build /bin
21+
COPY --from=builder /app/build/server /bin/server
22+
COPY run.sh /bin/run.sh
23+
RUN chmod +x /bin/run.sh
1224

1325
EXPOSE 8080
14-
CMD ["server"]
26+
CMD ["/bin/run.sh"]

frameworks/Dart/dart3/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: dartbenchmark
22
description: A benchmark of dart
33
environment:
4-
sdk: ^3.8.0
4+
sdk: ^3.10.7
55

66
dev_dependencies:
7-
lints: ^4.0.0
7+
lints: ^6.0.0

frameworks/Dart/dart3/run.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
# Detect CPU threads from the system
3+
TOTAL_CORES=$(grep -c ^processor /proc/cpuinfo)
4+
5+
# This comes from the ENV in the Dockerfile
6+
MAX_ISO=${MAX_ISOLATES_PER_PROCESS}
7+
8+
# Calculate OS processes needed
9+
NUM_WORKERS=$((TOTAL_CORES / MAX_ISO))
10+
if [ "$NUM_WORKERS" -le 0 ]; then NUM_WORKERS=1; fi
11+
12+
echo "Scaling: $TOTAL_CORES cores / $MAX_ISO isolates = $NUM_WORKERS processes"
13+
14+
for i in $(seq 1 $NUM_WORKERS); do
15+
/bin/server &
16+
done
17+
18+
wait

0 commit comments

Comments
 (0)