diff --git a/frameworks/Dart/dart3/README.md b/frameworks/Dart/dart3/README.md index 3be261226e2..6e6b6ba304d 100644 --- a/frameworks/Dart/dart3/README.md +++ b/frameworks/Dart/dart3/README.md @@ -8,6 +8,17 @@ The tests were run with: ## Benchmark Variants +### JIT + +Simplest possible implementation utilizing the standard Dart VM. +Results in the highest footprint both in terms of image size and memory consumption. +([source code](https://github.com/TechEmpower/FrameworkBenchmarks/tree/master/frameworks/Dart/dart3/dart_jit)) + +Test URLs: + +- JSON: `http://localhost:8080/json` +- PLAINTEXT: `http://localhost:8080/plaintext` + ### Native Minimal implementation with the smallest resource footprint. diff --git a/frameworks/Dart/dart3/benchmark_config.json b/frameworks/Dart/dart3/benchmark_config.json index 2b3d7df97e1..3eed4aaaadc 100644 --- a/frameworks/Dart/dart3/benchmark_config.json +++ b/frameworks/Dart/dart3/benchmark_config.json @@ -25,6 +25,18 @@ "language": "Dart", "os": "Linux", "database_os": "Linux" + }, + "jit": { + "display_name": "dart3_jit", + "json_url": "/json", + "plaintext_url": "/plaintext", + "port": 8080, + "approach": "Stripped", + "classification": "Platform", + "database": "None", + "language": "Dart", + "os": "Linux", + "database_os": "Linux" } }] } \ No newline at end of file diff --git a/frameworks/Dart/dart3/dart3-aot.dockerfile b/frameworks/Dart/dart3/dart3-aot.dockerfile index ef9d633eadf..5e6b2f70fb6 100644 --- a/frameworks/Dart/dart3/dart3-aot.dockerfile +++ b/frameworks/Dart/dart3/dart3-aot.dockerfile @@ -4,8 +4,7 @@ WORKDIR /app ARG MAX_ISOLATES=8 -COPY pubspec.yaml . -COPY dart_aot/bin/ bin/ +COPY dart_aot/ . RUN dart compile aot-snapshot bin/server.dart \ --define=MAX_ISOLATES=${MAX_ISOLATES} \ diff --git a/frameworks/Dart/dart3/dart3-jit.dockerfile b/frameworks/Dart/dart3/dart3-jit.dockerfile new file mode 100644 index 00000000000..f701ca2bbec --- /dev/null +++ b/frameworks/Dart/dart3/dart3-jit.dockerfile @@ -0,0 +1,8 @@ + +FROM dart:3.11.0 AS build +WORKDIR /app + +COPY dart_jit/ . + +EXPOSE 8080 +ENTRYPOINT ["dart", "run", "bin/server.dart"] \ No newline at end of file diff --git a/frameworks/Dart/dart3/dart3.dockerfile b/frameworks/Dart/dart3/dart3.dockerfile index 6b9a5b82753..1e47ebff2ef 100644 --- a/frameworks/Dart/dart3/dart3.dockerfile +++ b/frameworks/Dart/dart3/dart3.dockerfile @@ -2,8 +2,7 @@ FROM dart:3.11.0 AS build WORKDIR /app -COPY pubspec.yaml . -COPY dart_native/bin/ bin/ +COPY dart_native/ . RUN dart compile exe bin/server.dart -o server diff --git a/frameworks/Dart/dart3/analysis_options.yaml b/frameworks/Dart/dart3/dart_aot/analysis_options.yaml similarity index 100% rename from frameworks/Dart/dart3/analysis_options.yaml rename to frameworks/Dart/dart3/dart_aot/analysis_options.yaml diff --git a/frameworks/Dart/dart3/dart_aot/bin/server.dart b/frameworks/Dart/dart3/dart_aot/bin/server.dart index 4b0f1064942..2c1798730ea 100755 --- a/frameworks/Dart/dart3/dart_aot/bin/server.dart +++ b/frameworks/Dart/dart3/dart_aot/bin/server.dart @@ -25,11 +25,6 @@ final _jsonEncoder = JsonUtf8Encoder(); /// belong to a secondary "worker group". const _workerGroupTag = '--WORKER-GROUP'; -/// The maximum duration allowed for a single HTTP request to be processed. -/// This prevents slow clients or stalled logic from blocking the isolate's -/// event loop indefinitely. -const _requestTimeout = Duration(seconds: 8); - void main(List arguments) async { /// Create a mutable copy of the fixed-length arguments list. final args = [...arguments]; @@ -91,22 +86,14 @@ Future _startServer(List args) async { server ..defaultResponseHeaders.clear() /// Sets [HttpServer]'s [serverHeader]. - ..serverHeader = 'dart_aot'; - - /// Handles [HttpRequest]'s from [HttpServer]. - await for (final request in server) { - /// Asynchronously processes each request with an 8-second safety deadline - /// to prevent stalled connections from blocking the isolate event loop. - await _handleRequest(request).timeout( - _requestTimeout, - onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout), - ); - } + ..serverHeader = 'dart_aot' + /// Handles [HttpRequest]'s from [HttpServer]. + ..listen(_handleRequest); } /// Dispatches requests to specific test handlers. Wrapped in a try-catch /// to ensure stable execution and guaranteed response delivery. -Future _handleRequest(HttpRequest request) async { +void _handleRequest(HttpRequest request) { try { switch (request.uri.path) { case '/json': diff --git a/frameworks/Dart/dart3/pubspec.yaml b/frameworks/Dart/dart3/dart_aot/pubspec.yaml similarity index 52% rename from frameworks/Dart/dart3/pubspec.yaml rename to frameworks/Dart/dart3/dart_aot/pubspec.yaml index aeb53912216..020b4166287 100644 --- a/frameworks/Dart/dart3/pubspec.yaml +++ b/frameworks/Dart/dart3/dart_aot/pubspec.yaml @@ -1,5 +1,5 @@ -name: dartbenchmark -description: A benchmark of dart +name: dart_aot_benchmark +description: A benchmark of Dart environment: sdk: ^3.11.0 diff --git a/frameworks/Dart/dart3/dart_jit/analysis_options.yaml b/frameworks/Dart/dart3/dart_jit/analysis_options.yaml new file mode 100644 index 00000000000..926fdf8d193 --- /dev/null +++ b/frameworks/Dart/dart3/dart_jit/analysis_options.yaml @@ -0,0 +1,3 @@ +include: package:lints/recommended.yaml +formatter: + trailing_commas: preserve diff --git a/frameworks/Dart/dart3/dart_jit/bin/server.dart b/frameworks/Dart/dart3/dart_jit/bin/server.dart new file mode 100755 index 00000000000..9ee80ee6ab3 --- /dev/null +++ b/frameworks/Dart/dart3/dart_jit/bin/server.dart @@ -0,0 +1,87 @@ +import 'dart:convert'; +import 'dart:io'; + +/// The fixed TCP port used by the server. +/// Defined here for visibility and ease of configuration. +const _defaultPort = 8080; + +/// A reusable instance of the UTF-8 JSON encoder to efficiently +/// transform Dart objects into byte arrays for HTTP responses. +final _jsonEncoder = JsonUtf8Encoder(); + +void main(List args) async { + /// Binds the [HttpServer] on `0.0.0.0:8080`. + final server = await HttpServer.bind( + InternetAddress.anyIPv4, + _defaultPort, + ); + + server + ..defaultResponseHeaders.clear() + /// Sets [HttpServer]'s [serverHeader]. + ..serverHeader = 'dart_jit' + /// Handles [HttpRequest]'s from [HttpServer]. + ..listen(_handleRequest); +} + +/// Dispatches requests to specific test handlers. Wrapped in a try-catch +/// to ensure stable execution and guaranteed response delivery. +void _handleRequest(HttpRequest request) { + try { + switch (request.uri.path) { + case '/json': + _jsonTest(request); + break; + case '/plaintext': + _plaintextTest(request); + break; + default: + _sendResponse(request, HttpStatus.notFound); + } + } catch (e) { + _sendResponse(request, HttpStatus.internalServerError); + } +} + +/// Completes the given [request] by writing the [bytes] with the given +/// [statusCode] and [type]. +void _sendResponse( + HttpRequest request, + int statusCode, { + ContentType? type, + List bytes = const [], +}) => request.response + ..statusCode = statusCode + ..headers.contentType = type + ..headers.date = DateTime.now() + ..contentLength = bytes.length + ..add(bytes) + ..close(); + +/// Completes the given [request] by writing the [response] as JSON. +void _sendJson(HttpRequest request, Object response) => _sendResponse( + request, + HttpStatus.ok, + type: ContentType.json, + bytes: _jsonEncoder.convert(response), +); + +/// Completes the given [request] by writing the [response] as plain text. +void _sendText(HttpRequest request, String response) => _sendResponse( + request, + HttpStatus.ok, + type: ContentType.text, + bytes: utf8.encode(response), +); + +/// Responds with the JSON test to the [request]. +void _jsonTest(HttpRequest request) => _sendJson( + request, + const {'message': 'Hello, World!'}, +); + +/// Responds with the plaintext test to the [request]. +void _plaintextTest(HttpRequest request) => _sendText( + request, + 'Hello, World!', +); diff --git a/frameworks/Dart/dart3/dart_jit/pubspec.yaml b/frameworks/Dart/dart3/dart_jit/pubspec.yaml new file mode 100644 index 00000000000..872ebfd838c --- /dev/null +++ b/frameworks/Dart/dart3/dart_jit/pubspec.yaml @@ -0,0 +1,8 @@ +name: dart_jit_benchmark +description: A benchmark of Dart +environment: + sdk: ^3.11.0 + +dev_dependencies: + lints: ^6.1.0 + diff --git a/frameworks/Dart/dart3/dart_native/analysis_options.yaml b/frameworks/Dart/dart3/dart_native/analysis_options.yaml new file mode 100644 index 00000000000..926fdf8d193 --- /dev/null +++ b/frameworks/Dart/dart3/dart_native/analysis_options.yaml @@ -0,0 +1,3 @@ +include: package:lints/recommended.yaml +formatter: + trailing_commas: preserve diff --git a/frameworks/Dart/dart3/dart_native/bin/server.dart b/frameworks/Dart/dart3/dart_native/bin/server.dart index 029c6eaee1d..eb1cefab75b 100755 --- a/frameworks/Dart/dart3/dart_native/bin/server.dart +++ b/frameworks/Dart/dart3/dart_native/bin/server.dart @@ -10,11 +10,6 @@ const _defaultPort = 8080; /// transform Dart objects into byte arrays for HTTP responses. final _jsonEncoder = JsonUtf8Encoder(); -/// The maximum duration allowed for a single HTTP request to be processed. -/// This prevents slow clients or stalled logic from blocking the isolate's -/// event loop indefinitely. -const _requestTimeout = Duration(seconds: 8); - void main(List args) async { /// Create an [Isolate] containing an [HttpServer] /// for each processor after the first @@ -38,22 +33,14 @@ Future _startServer(List args) async { server ..defaultResponseHeaders.clear() /// Sets [HttpServer]'s [serverHeader]. - ..serverHeader = 'dart_native'; - - /// Handles [HttpRequest]'s from [HttpServer]. - await for (final request in server) { - /// Asynchronously processes each request with an 8-second safety deadline - /// to prevent stalled connections from blocking the isolate event loop. - await _handleRequest(request).timeout( - _requestTimeout, - onTimeout: () => _sendResponse(request, HttpStatus.requestTimeout), - ); - } + ..serverHeader = 'dart_native' + /// Handles [HttpRequest]'s from [HttpServer]. + ..listen(_handleRequest); } /// Dispatches requests to specific test handlers. Wrapped in a try-catch /// to ensure stable execution and guaranteed response delivery. -Future _handleRequest(HttpRequest request) async { +void _handleRequest(HttpRequest request) { try { switch (request.uri.path) { case '/json': diff --git a/frameworks/Dart/dart3/dart_native/pubspec.yaml b/frameworks/Dart/dart3/dart_native/pubspec.yaml new file mode 100644 index 00000000000..a6016fd875a --- /dev/null +++ b/frameworks/Dart/dart3/dart_native/pubspec.yaml @@ -0,0 +1,8 @@ +name: dart_native_benchmark +description: A benchmark of Dart +environment: + sdk: ^3.11.0 + +dev_dependencies: + lints: ^6.1.0 +