Skip to content
This repository was archived by the owner on Feb 11, 2024. It is now read-only.

Commit 3fe163a

Browse files
benchmark: maintain no. of parallel requests in throughput benchmark (#17)
1 parent 80df427 commit 3fe163a

File tree

5 files changed

+52
-47
lines changed

5 files changed

+52
-47
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
This package binds to Cronet's [native API](https://chromium.googlesource.com/chromium/src/+/master/components/cronet/native/test_instructions.md) to expose them in Dart.
44

5-
This is an HTTP Client Package with [almost](dart_io_comparison.md#api-comparison) the same API as `dart:io`. By comparison, `package:cronet` is capable of serving [about 4 to 5 times](dart_io_comparison.md#throughput-parallel-requests) more parallel network requests than `dart:io` and on par in making sequential network requests.
6-
75
This is a [GSoC 2021 project](https://summerofcode.withgoogle.com/projects/#4757095741652992).
86

97
## Supported Platforms

benchmark/latency.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class LatencyBenchmark {
2020
await run();
2121
}
2222

23-
static Future<double> measureFor(Function f, Duration duration) async {
23+
Future<double> measureFor(Function f, Duration duration) async {
2424
var durationInMilliseconds = duration.inMilliseconds;
2525
var iter = 0;
2626
var watch = Stopwatch();

benchmark/run_all.dart

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ void main(List<String> args) async {
118118
print('| AOT | ${aotCronetLatency.toStringAsFixed(3)} ms |'
119119
' ${aotDartIOLatency.toStringAsFixed(3)} ms |');
120120
print('\nThroughput Test Results (Duration: ${duration.inSeconds}s)');
121-
print('| Mode | package:cronet | dart:io |');
122-
print('| :-----------: |:--------------: | :-----------: |');
123-
print('| JIT | ${jitCronetThroughput[1]} out of'
124-
' ${jitCronetThroughput[0]} | ${jitDartIOThroughput[1]} out of'
125-
' ${jitDartIOThroughput[0]} |');
126-
print('| AOT | ${aotCronetThroughput[1]} out of'
127-
' ${aotCronetThroughput[0]} | ${aotDartIOThroughput[1]} out of'
128-
' ${aotDartIOThroughput[0]} |');
121+
print('Considering the best appearing value only');
122+
print('| Mode | package:cronet | dart:io |');
123+
print('| :--: |:-------------------------: | :----------------------: |');
124+
print('| JIT | ${jitCronetThroughput[1]} (Parallel Requests:'
125+
' ${jitCronetThroughput[0]})| ${jitDartIOThroughput[1]}'
126+
' (Parallel Requests: ${jitDartIOThroughput[0]})|');
127+
print('| AOT | ${aotCronetThroughput[1]} (Parallel Requests: '
128+
' ${aotCronetThroughput[0]})| ${aotDartIOThroughput[1]}'
129+
' (Parallel Requests: ${aotDartIOThroughput[0]})|');
129130
}

benchmark/throughput.dart

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,47 @@ import 'package:cronet/cronet.dart';
1111

1212
abstract class ThroughputBenchmark {
1313
final String url;
14-
final int spawnThreshold;
14+
final int parallelLimit;
1515
final Duration duration;
1616

1717
Future<void> run();
1818
void setup();
1919
void teardown();
2020
Future<void> warmup();
2121

22-
ThroughputBenchmark(this.url, this.spawnThreshold, this.duration);
22+
ThroughputBenchmark(this.url, this.parallelLimit, this.duration);
2323

24-
static Future<List<int>> measureFor(
25-
Future<void> Function() f, Duration duration, int maxSpawn) async {
24+
Future<List<int>> measureFor(
25+
Future<void> Function() f, Duration duration, int parallelLimit) async {
2626
var durationInMicroseconds = duration.inMicroseconds;
2727
var inTimeReturns = 0;
2828
var lateReturns = 0;
29+
var spawned = 0;
2930
var watch = Stopwatch();
3031
final completer = Completer<List<int>>();
31-
watch.start();
32-
for (int i = 0; i < maxSpawn; i++) {
33-
f().then((_) {
34-
if (watch.elapsedMicroseconds < durationInMicroseconds) {
35-
inTimeReturns++;
36-
} else {
37-
watch.stop();
32+
33+
FutureOr<void> _measureAndRespawn(void _) {
34+
if (watch.elapsedMicroseconds < durationInMicroseconds) {
35+
inTimeReturns++;
36+
f().then(_measureAndRespawn).onError((error, stackTrace) {
3837
lateReturns++;
38+
});
39+
spawned++;
40+
} else {
41+
watch.stop();
42+
lateReturns++;
43+
if (inTimeReturns + lateReturns == spawned) {
44+
completer.complete([parallelLimit, inTimeReturns]);
3945
}
40-
if (inTimeReturns + lateReturns == maxSpawn) {
41-
completer.complete([maxSpawn, inTimeReturns]);
42-
}
43-
}).onError((error, stackTrace) {});
46+
}
47+
}
48+
49+
watch.start();
50+
for (int i = 0; i < parallelLimit; i++) {
51+
f().then(_measureAndRespawn).onError((error, stackTrace) {
52+
lateReturns++;
53+
});
54+
spawned++;
4455
}
4556
return completer.future;
4657
}
@@ -58,12 +69,12 @@ abstract class ThroughputBenchmark {
5869
Future<List<int>> report() async {
5970
var maxReturn = 0;
6071
var throughput = [0, 0];
61-
// Run the benchmark for 1, 2, 4...spawnThreshold.
72+
// Run the benchmark for 1, 2, 4...parallelLimit.
6273
for (int currentThreshold = 1;
63-
currentThreshold <= spawnThreshold;
74+
currentThreshold <= parallelLimit;
6475
currentThreshold *= 2) {
6576
final res = await measure(currentThreshold);
66-
print('$runtimeType: Total Spawned: ${res[0]},'
77+
print('$runtimeType: Parallel Requests: ${res[0]},'
6778
' Returned in time: ${res[1]}.');
6879
if (res[1] > maxReturn) {
6980
maxReturn = res[1];

dart_io_comparison.md

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ Payload: Lorem Ipsum Text
3333
| JIT | 1.807 ms | **1.801 ms** |
3434
| AOT | 1.441 ms | **1.049 ms** |
3535

36+
Server: HTTP/2 example.com Server
37+
Payload: example.com index.html page
38+
39+
| Mode | package:cronet | dart:io |
40+
| :-----------: |:-------------: | :------------: |
41+
| JIT | **90.696 ms** | 104.150 ms |
42+
| AOT | **89.348 ms** | 104.050 ms |
43+
3644
Server: HTTP/2 Google Server
3745
Payload: Google Chrome Debian Package
3846

@@ -43,24 +51,11 @@ Payload: Google Chrome Debian Package
4351

4452
### Throughput (Parallel Requests)
4553

46-
_Contents written as, x concurrent requests succesfully completed out of y requests spawned within 1 second._
47-
48-
Server: HTTP/2 Local Caddy Server
49-
Payload: example.org 's index.html page
50-
51-
| Mode | package:cronet | dart:io |
52-
| :-----------: |:------------------:| :--------------:|
53-
| JIT |**2982 out of 4096**| 512 out of 512 |
54-
| AOT |**2883 out of 4096**| 512 out of 512 |
55-
56-
*`dart:io`'s successful requests went down to 1 when more than 512 requests are spawned.*
57-
5854
Server: HTTP/2 example.com Server
5955
Payload: example.com index.html page
6056

61-
| Mode | package:cronet | dart:io |
62-
| :-----------: |:------------------:| :-------------:|
63-
| JIT |**178 out of 512** | 39 out of 128 |
64-
| AOT |**214 out of 512** | 49 out of 128 |
65-
66-
*These are the best results. `dart:io`'s successful requests went down to rapidly to 0 as we reach 512 requests mark.*
57+
Considering the best appearing value only
58+
| Mode | package:cronet | dart:io |
59+
| :--: |:-------------------------: | :----------------------: |
60+
| JIT | 855 (Parallel Requests: 256) | 1078 (Parallel Requests: 256)|
61+
| AOT | 789 (Parallel Requests: 128) | 1306 (Parallel Requests: 512)|

0 commit comments

Comments
 (0)