grafana / k6-jslib-aws

Javascript Library allowing to interact with AWS resources from k6 scripts
Apache License 2.0
18 stars 29 forks source link

open() performance #3

Closed QAInsights closed 2 years ago

QAInsights commented 2 years ago

Hi Team,

As per the example code, it uses const testFile = open('./bonjour.txt', 'r') open(). But as per the documentation, it suggests the usage of SharedArray.

Could you please clarify which is ideal for AWS? Thanks!

oleiade commented 2 years ago

Hi @QAInsights,

You're right, the documentation is probably misleading in this specific scenario.

To offer you the best support, would you be able to tell me more about your use case? An example script would be even better if that's possible.

I realize the README examples are not up-to-date with the documentation itself (going to work on that) and might be misleading because they do not represent real-world scripts. In general, whenever possible, SharedArray should indeed be used.

QAInsights commented 2 years ago

Thanks @oleiade One of my use cases is, after executing the k6 script, I would like to upload my results (in CSV, JSON, or HTML) to S3. In this case, is using open() ideal, considering the file size for a simple load testing.

But for endurance testing, the duration would be like days. So, in this case, I believe using SharedArray() makes sense?

Thoughts?

oleiade commented 2 years ago

Unless I missed some aspect of your use case, you should be able to get away without using open(), nor SharedArray. In fact, you should be able to use S3Client.putObject with the summary data directly in the handleSummary() function (which is called only once at the end of the execution.

Would something along the lines of the following fit your use case?

import http from "k6/http";
import { check } from "k6";
import { AWSConfig, S3Client } from "https://jslib.k6.io/aws/0.3.0/s3.js";

const awsConfig = new AWSConfig(
  __ENV.AWS_REGION,
  __ENV.AWS_ACCESS_KEY_ID,
  __ENV.AWS_SECRET_ACCESS_KEY
);

const s3 = new S3Client(awsConfig);

export default function () {
  let res = http.get("https://test-api.k6.io");
  check(res, { "is status 200": (r) => r.status === 200 });
}

export function handleSummary(data) {
  s3.putObject("myBucket", "myResultsKey", JSON.stringify(data));
}