Book Image

Dart By Example

By : David Mitchell
Book Image

Dart By Example

By: David Mitchell

Overview of this book

Table of Contents (17 chapters)
Dart By Example
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Load testing


It is good to know the limits of an application long before you ever reach them. The HttpClientRequest function can be used to create requests to the blog server, and the HttpClientResponse function can be used to receive incoming data from the blog server.

The statusCode property will be checked to ensure that the page request was successfully handled by the server.

Building a simple load tool

A simple benchmark for the blog server would be the time taken to serve 1000 files. The getUrl method triggers the actual request with the first then clause, closing the request to the server. The following then clause handles the actual response from the server.

This method can be used to monitor a live website and perhaps trigger a notification if a status other than HttpStatus.OK is received:

import 'dart:io';

main() {
  print("Starting...");

  var url = "http://127.0.0.1:8080/index.html";
  var hc = new HttpClient();
  var watch = new Stopwatch();
  int attemptedRequests = 1000;

  print...