- Dart:Scalable Application Development
- Davy Mitchell Sergey Akopkokhyants Ivo Balbaert
- 209字
- 2021-07-09 18:56:24
Load testing revisited
The initial load testing application was rather limited, and though of use, it did not give a realistic picture with so many requests thrown at once at the server application without waiting for a response.
Updating the load tester
The new version of the load testing application will make a single HTTP call and await the result before calling the next. This takes place in the main.dart
source file. Note that the main function itself in now marked as async
. The await
command is used in the calling loop of the main
function, as follows:
main() async { print("Starting..."); var url = "http://127.0.0.1:8080/index.html"; var hc = new HttpClient(); var watch = new Stopwatch(); int attemptedRequests = 200; print("Starting testing..."); watch.start(); for (int i = 0; i < attemptedRequests; i++) { await callWebPage(hc, url, i, watch); } watch.stop(); print("${watch.elapsed.inMilliseconds}"); }
The callWebPage
method needs to be marked as async
too, as await
will be used twice:
callWebPage(HttpClient webClient, String targetURL, int requestNumber, Stopwatch watch) async { HttpClientRequest request; HttpClientResponse response; request = await webClient.getUrl(Uri.parse(targetURL)); response = await request.close(); print("$requestNumber, ${response.statusCode}, ${watch.elapsed.inMilliseconds}"); }
The two operations of unknown duration, the URL fetch and closing of the response, are waited upon before the output to the screen is processed.
推薦閱讀
- Web程序設(shè)計(jì)及應(yīng)用
- Raspberry Pi Networking Cookbook(Second Edition)
- C/C++算法從菜鳥(niǎo)到達(dá)人
- Python進(jìn)階編程:編寫更高效、優(yōu)雅的Python代碼
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- H5頁(yè)面設(shè)計(jì):Mugeda版(微課版)
- Mastering Linux Network Administration
- HTML5 APP開(kāi)發(fā)從入門到精通(微課精編版)
- C#程序設(shè)計(jì)教程(第3版)
- Access 2010數(shù)據(jù)庫(kù)應(yīng)用技術(shù)實(shí)驗(yàn)指導(dǎo)與習(xí)題選解(第2版)
- Hands-On JavaScript for Python Developers
- Photoshop CC移動(dòng)UI設(shè)計(jì)案例教程(全彩慕課版·第2版)
- Qt 4開(kāi)發(fā)實(shí)踐
- Mastering JavaScript
- 深入理解Kafka:核心設(shè)計(jì)與實(shí)踐原理