官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 蛟河市| 邯郸县| 固镇县| 遂溪县| 尉氏县| 开远市| 龙口市| 如东县| 茌平县| 南溪县| 丰都县| 洛隆县| 石林| 吉安市| 凉山| 泾川县| 青河县| 楚雄市| 南漳县| 安义县| 淳安县| 离岛区| 乡城县| 南岸区| 无棣县| 元朗区| 贵溪市| 崇文区| 栖霞市| 乌兰察布市| 井陉县| 周宁县| 兰坪| 莒南县| 美姑县| 本溪市| 措勤县| 即墨市| 合山市| 离岛区| 阿鲁科尔沁旗|