Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frameworks/Dart/dart3/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dart 3 Benchmarking Test

### Test Type Implementation Source Code
## Test Type Implementation Source Code

- [JSON](server.dart)
- [PLAINTEXT](server.dart)
Expand All @@ -9,14 +9,14 @@

The tests were run with:

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

## Test URLs

### JSON

http://localhost:8080/json
`http://localhost:8080/json`

### PLAINTEXT

http://localhost:8080/plaintext
`http://localhost:8080/plaintext`
10 changes: 9 additions & 1 deletion frameworks/Dart/dart3/bin/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ import 'dart:io';
import 'dart:isolate';

void main(List<String> args) async {
/// Isolate count per process, set at build-time via:
/// dart compile exe --define=MAX_ISOLATES=X
/// Defaults to machine core count for dynamic scaling.
final maxIsolates = int.fromEnvironment(
'MAX_ISOLATES',
defaultValue: Platform.numberOfProcessors,
);

/// Create an [Isolate] containing an [HttpServer]
/// for each processor after the first
for (var i = 1; i < Platform.numberOfProcessors; i++) {
for (var i = 1; i < maxIsolates; i++) {
await Isolate.spawn(_startServer, args);
}

Expand Down
26 changes: 19 additions & 7 deletions frameworks/Dart/dart3/dart3.dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@

FROM dart:3.8 AS builder

COPY . /app
FROM dart:3.10.7 AS builder
WORKDIR /app

# Define the build-time argument (Default to 8)
ARG MAX_ISOLATES=8
COPY . .
RUN mkdir build
RUN dart compile exe ./bin/server.dart -o build/server
RUN dart compile exe bin/server.dart \
--define=MAX_ISOLATES=${MAX_ISOLATES} \
-o build/server

FROM busybox:glibc

# Re-declare ARG in the second stage to use it in ENV
# Define the build-time argument (Default to 8)
ARG MAX_ISOLATES=8
ENV MAX_ISOLATES_PER_PROCESS=${MAX_ISOLATES}

FROM scratch
COPY --from=builder /runtime/ /
COPY --from=builder /app/build /bin
COPY --from=builder /app/build/server /bin/server
COPY run.sh /bin/run.sh
RUN chmod +x /bin/run.sh

EXPOSE 8080
CMD ["server"]
CMD ["/bin/run.sh"]
4 changes: 2 additions & 2 deletions frameworks/Dart/dart3/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: dartbenchmark
description: A benchmark of dart
environment:
sdk: ^3.8.0
sdk: ^3.10.7

dev_dependencies:
lints: ^4.0.0
lints: ^6.0.0
18 changes: 18 additions & 0 deletions frameworks/Dart/dart3/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/sh
# Detect CPU threads from the system
TOTAL_CORES=$(grep -c ^processor /proc/cpuinfo)

# This comes from the ENV in the Dockerfile
MAX_ISO=${MAX_ISOLATES_PER_PROCESS}

# Calculate OS processes needed
NUM_WORKERS=$((TOTAL_CORES / MAX_ISO))
if [ "$NUM_WORKERS" -le 0 ]; then NUM_WORKERS=1; fi

echo "Scaling: $TOTAL_CORES cores / $MAX_ISO isolates = $NUM_WORKERS processes"

for i in $(seq 1 $NUM_WORKERS); do
/bin/server &
done

wait
Loading