2017-08-03 16:40:21 +00:00
|
|
|
/// A basic server that prints "Hello, world!"
|
|
|
|
library performance.hello;
|
|
|
|
|
2017-11-18 17:42:31 +00:00
|
|
|
import 'dart:async';
|
2017-08-03 16:40:21 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'dart:isolate';
|
|
|
|
import 'package:angel_framework/angel_framework.dart';
|
|
|
|
|
2017-11-28 18:14:50 +00:00
|
|
|
main() async {
|
|
|
|
var isolates = <Isolate>[];
|
|
|
|
|
2017-11-18 17:42:31 +00:00
|
|
|
for (int i = 0; i < Platform.numberOfProcessors; i++) {
|
2017-11-28 18:14:50 +00:00
|
|
|
isolates.add(await Isolate.spawn(start, i + 1));
|
2017-10-28 08:50:16 +00:00
|
|
|
}
|
|
|
|
|
2017-11-28 18:14:50 +00:00
|
|
|
await Future.wait(isolates.map((i) {
|
|
|
|
var rcv = new ReceivePort();
|
|
|
|
i.addOnExitListener(rcv.sendPort);
|
|
|
|
return rcv.first;
|
|
|
|
}));
|
|
|
|
//start(0);
|
2017-08-03 16:40:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void start(int id) {
|
2017-11-28 18:14:50 +00:00
|
|
|
var app = new Angel.custom(startShared)..lazyParseBodies = true;
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
app.get('/', (req, ResponseContext res) {
|
|
|
|
res.willCloseItself = true;
|
|
|
|
res.io
|
|
|
|
..write('Hello, world!')
|
|
|
|
..close();
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
app.get('/', (req, ResponseContext res) {
|
|
|
|
res.useStream();
|
|
|
|
res.write('Hello, world!');
|
|
|
|
});
|
|
|
|
}
|
2017-09-22 14:53:49 +00:00
|
|
|
|
|
|
|
var oldHandler = app.errorHandler;
|
|
|
|
app.errorHandler = (e, req, res) {
|
|
|
|
print('Oops: ${e.error ?? e}');
|
|
|
|
print(e.stackTrace);
|
|
|
|
return oldHandler(e, req, res);
|
|
|
|
};
|
2017-08-03 16:40:21 +00:00
|
|
|
app.startServer(InternetAddress.LOOPBACK_IP_V4, 3000).then((server) {
|
|
|
|
print(
|
|
|
|
'Instance #$id listening at http://${server.address.address}:${server.port}');
|
|
|
|
});
|
|
|
|
}
|