1
0
mirror of https://github.com/dart-lang/sdk synced 2024-07-01 07:14:29 +00:00

[vm/concurrency] Add IsolateBaseOverhead benchmark

Issue b/190877061

TEST=ci

Change-Id: Ifa570492b440849252a9bd01c7782656bcce7fd2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245984
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
This commit is contained in:
Martin Kustermann 2022-05-30 08:14:52 +00:00 committed by Commit Bot
parent 58ae856422
commit e566f9a14b
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,56 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
const int count = 10000;
// The benchmark will spawn a long chain of isolates, keeping all of them
// alive until the last one which measures Rss at that point (i.e. when all
// isolates are alive), thereby getting a good estimate of memory-overhead per
// isolate.
void main() async {
final onDone = ReceivePort();
final lastIsolatePort = ReceivePort();
final startRss = ProcessInfo.currentRss;
final startUs = DateTime.now().microsecondsSinceEpoch;
await Isolate.spawn(worker, WorkerInfo(count, lastIsolatePort.sendPort),
onExit: onDone.sendPort);
final result = await lastIsolatePort.first as List;
final lastIsolateRss = result[0] as int;
final lastIsolateUs = result[1] as int;
await onDone.first;
final doneUs = DateTime.now().microsecondsSinceEpoch;
final averageMemoryUsageInKB = (lastIsolateRss - startRss) / count / 1024;
final averageStartLatencyInUs = (lastIsolateUs - startUs) / count;
final averageFinishLatencyInUs = (doneUs - startUs) / count;
print('IsolateBaseOverhead.Rss(MemoryUse): $averageMemoryUsageInKB');
print(
'IsolateBaseOverhead.StartLatency(Latency): $averageStartLatencyInUs us.');
print(
'IsolateBaseOverhead.FinishLatency(Latency): $averageFinishLatencyInUs us.');
}
class WorkerInfo {
final int id;
final SendPort result;
WorkerInfo(this.id, this.result);
}
Future worker(WorkerInfo workerInfo) async {
if (workerInfo.id == 1) {
workerInfo.result
.send([ProcessInfo.currentRss, DateTime.now().microsecondsSinceEpoch]);
return;
}
final onExit = ReceivePort();
await Isolate.spawn(worker, WorkerInfo(workerInfo.id - 1, workerInfo.result),
onExit: onExit.sendPort);
await onExit.first;
}

View File

@ -0,0 +1,56 @@
// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'dart:isolate';
const int count = 10000;
// The benchmark will spawn a long chain of isolates, keeping all of them
// alive until the last one which measures Rss at that point (i.e. when all
// isolates are alive), thereby getting a good estimate of memory-overhead per
// isolate.
void main() async {
final onDone = ReceivePort();
final lastIsolatePort = ReceivePort();
final startRss = ProcessInfo.currentRss;
final startUs = DateTime.now().microsecondsSinceEpoch;
await Isolate.spawn(worker, WorkerInfo(count, lastIsolatePort.sendPort),
onExit: onDone.sendPort);
final result = await lastIsolatePort.first as List;
final lastIsolateRss = result[0] as int;
final lastIsolateUs = result[1] as int;
await onDone.first;
final doneUs = DateTime.now().microsecondsSinceEpoch;
final averageMemoryUsageInKB = (lastIsolateRss - startRss) / count / 1024;
final averageStartLatencyInUs = (lastIsolateUs - startUs) / count;
final averageFinishLatencyInUs = (doneUs - startUs) / count;
print('IsolateBaseOverhead.Rss(MemoryUse): $averageMemoryUsageInKB');
print(
'IsolateBaseOverhead.StartLatency(Latency): $averageStartLatencyInUs us.');
print(
'IsolateBaseOverhead.FinishLatency(Latency): $averageFinishLatencyInUs us.');
}
class WorkerInfo {
final int id;
final SendPort result;
WorkerInfo(this.id, this.result);
}
Future worker(WorkerInfo workerInfo) async {
if (workerInfo.id == 1) {
workerInfo.result
.send([ProcessInfo.currentRss, DateTime.now().microsecondsSinceEpoch]);
return;
}
final onExit = ReceivePort();
await Isolate.spawn(worker, WorkerInfo(workerInfo.id - 1, workerInfo.result),
onExit: onExit.sendPort);
await onExit.first;
}

View File

@ -224,6 +224,9 @@ class Isolate {
///
/// Returns a future which will complete with an [Isolate] instance if the
/// spawning succeeded. It will complete with an error otherwise.
///
/// One can expect the base memory overhead of an isolate to be in the order
/// of 30 kb.
external static Future<Isolate> spawn<T>(
void entryPoint(T message), T message,
{bool paused = false,