Writing Custom Load Tests

A language specific load test is

  • ANY code you want to execute
  • With some redline13 API calls to report test execution and timing

Each language is documented independently and can be found on the corresponding page

Submitting Performance Tests

  • There are two ways to submit a custom load test
    • Submit the Load Test File ([ANY_NAME]..php ) in the language specified
    • Submit a compressed file (.tar, .tar.gz, .tgz ) with the custom file specifically named
      • PHP – Custom.class.php
  • Custom Load Tests support CSV, Compressed, and Extra files
    • CSV files can be split across servers
    • Compressed files can be marked to be expanded
    • All files are placed in the root of the load test

Package Support in Load Tests

Each Language supports a packaging mechanism to install more packages

  • PHP – Composer Plugin
  • Just include your composer.json file and we handle running composer command.

Versioning

  • PHP 5.5.9
  • Other versions required?  email info@redline13.com

Test Harness for local testing

A Test Harness is available for all languages, including examples

PHP Test

To write a custom load test in PHP, you need to create a single PHP file that contains a class named CustomTest that extends class LoadTestingTest. The constructor for CustomTest will be called with 2 parameters, a test number and a random string, both of which should be passed to the constructor for LoadTestingTest. An instance of this class will be started for each user specified in the “Number of User” form field.

Documentation for the LoadTestingTest class and other helper classes can be found at https://www.redline13.com/customTestDoc/index.html. You must override the startTest() method of LoadTestingTest. This function is called to start the load test.

There are several reporting functions that are available for your use.

  • recordPageTime($ts, $time, $error = false, $kb = 0) – This records and aggregates the total page load time for a request, with $ts being the UNIX timestamp when the request started and $time being the time to complete the request. This function is used in the UI to report the overall average response time. The goToUrl method of LoadTestingSession calls this for you.
    • $error – if your page is an ERROR you can differentiate it from a success, yet still record page time.
    • $kb – record size of your response
  • recordURLPageLoad($url, $ts, $time, $error = false, $kb = 0) – This records and aggregates the total page load time for a request to a specific URL, with $ts being the UNIX timestamp when the request started and $time being the time to complete the request. This function is used in the UI to report the per page average response time, but does not affect the overall response time that is calculated. The goToUrl and loadResources methods of LoadTestingSession calls this for you.
    • $error – boolean to record if your result is fail or success
    • $kb – Size of response.
  • recordDownloadSize($kb) – This records the number of kilobytes downloaded for a request. The goToUrl and loadResources methods of LoadTestingSession calls this for you.
    • No longer needed if you record size in page or url calls.
    • Can be used to record non-page specific download size
  • recordError($error) – This records an error that will be displayed in the UI.
    • Can be used to record general errors
  • recordProgress($testNum, $percent) – This records the progress (between 0 and 100) of a single test. This allows you to enable more accurate progress than the default, which is based only on the number completed vs. the test size.

If a test fails, you can throw an Exception and the test will be marked as a failure.

Tips

  • To simulate the iterations parameter of a simple test, use a loop around your call(s) to goToUrl.
  • You can use the random string that is passed in as the second parameter to your CustomTest constructor to append to URLs. This can help you to easily identify load testing requests in your server logs.
  • If you need additional resources for your test, you can download a file (e.g. a .tgz) with the resources in the CustomTest constructor. You should include code to ensure that only one test per server downloads the files. If you know the number of tests per server, you can use the test number to decide which test should download the files. Alternatively, you can attempt to create a lock file, with the first process successfully creating the lock file doing the file download.