File tree Expand file tree Collapse file tree 5 files changed +52
-14
lines changed
Expand file tree Collapse file tree 5 files changed +52
-14
lines changed Original file line number Diff line number Diff line change 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 )
99
1010The 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 `
Original file line number Diff line number Diff line change @@ -3,9 +3,17 @@ import 'dart:io';
33import 'dart:isolate' ;
44
55void 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
Original file line number Diff line number Diff line change 11
2- FROM dart:3.8 AS builder
3-
4- COPY . /app
2+ FROM dart:3.10.7 AS builder
53WORKDIR /app
4+
5+ # Define the build-time argument (Default to 8)
6+ ARG MAX_ISOLATES=8
7+ COPY . .
68RUN 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
1020COPY --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
1325EXPOSE 8080
14- CMD ["server " ]
26+ CMD ["/bin/run.sh " ]
Original file line number Diff line number Diff line change 11name : dartbenchmark
22description : A benchmark of dart
33environment :
4- sdk : ^3.8.0
4+ sdk : ^3.10.7
55
66dev_dependencies :
7- lints : ^4 .0.0
7+ lints : ^6 .0.0
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments