Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open() performance #3

Closed
QAInsights opened this issue May 7, 2022 · 3 comments
Closed

open() performance #3

QAInsights opened this issue May 7, 2022 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@QAInsights
Copy link

QAInsights commented May 7, 2022

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 oleiade self-assigned this May 9, 2022
@oleiade oleiade added the documentation Improvements or additions to documentation label May 9, 2022
@oleiade
Copy link
Member

oleiade commented May 9, 2022

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
Copy link
Author

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
Copy link
Member

oleiade commented May 11, 2022

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));
}

@oleiade oleiade closed this as completed May 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants