artilleryio / artillery

The complete load testing platform. Everything you need for production-grade load tests. Serverless & distributed. Load test with Playwright. Load test HTTP APIs, GraphQL, WebSocket, and more. Use any Node.js module.
https://www.artillery.io
Mozilla Public License 2.0
7.91k stars 505 forks source link

How to emit response time in a custom function? #837

Open benel opened 4 years ago

benel commented 4 years ago

Hello !

@garnier5 and I discovered your great tool yesterday (thank you for it!).

In the process of including Puppeteer steps in Artillery scenarios, I started with a "toy" function trying to mimic the official get step.

Here is my code :

const fetch = require('node-fetch');

module.exports = {

  visitHome: async (context, events, done) => {
    let start = new Date().getTime();
    await fetch(context.vars.target)
      .then(x => x.text());
    events.emit('histogram', 'response_time', new Date().getTime() - start);
    return done();
  }

}
config:
  target: http://localhost:3000
  phases:
    - duration: 10
      arrivalRate: 20
  processor: ./custom.js

scenarios:
  - name: Discover the app
    flow:
      - function: visitHome

It results in:

Summary report @ 12:52:49(+0200) 2020-05-09
  Scenarios launched:  200
  Scenarios completed: 200
  Requests completed:  0
  Mean response/sec: NaN
  Response time (msec):
    min: NaN
    max: NaN
    median: NaN
    p95: NaN
    p99: NaN
  Scenario counts:
    Discover the app: 200 (100%)
  response_time:
    min: 2
    max: 34
    median: 3
    p95: 5
    p99: 14.5

Is it the right way to do this? What would be the right key to use so that measures are displayed in the official Response time (msec) ?

lancedolan commented 8 months ago

Having same issue. Right now I assume Response time and Mean response/sec are "out of the box" metrics you can only get by putting post or other flow commands into your scenario, such as

    flow:
      - post:
          url: "/pets"

Meanwhile, your flow which only consist of a function can only emit custom metrics. I'm doing the same.

🤷