Giter VIP home page Giter VIP logo

k6-jslib-formdata's Introduction

k6-jslib-formdata

FormData implements polyfill for k6.

This simplifies the creation of multipart/form-data requests from k6 scripts. It was adapted from the original version by Rob Wu to remove references of XMLHttpRequest and File related code which isn't supported in k6.

Usage

import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';

See the k6 documentation website for more details on how to use the FormData object.

k6-jslib-formdata's People

Contributors

amommersteeg-d2l avatar olegbespalov avatar oleiade avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

k6-jslib-formdata's Issues

FormData high CPU usage

The following test uses a lot of CPU, some basic analysis spots that the resources are used from the FormData polyfill's body method and specifically the line where the data are pushed into the raw Array used for joining the various parts. The same high consumption can be also observed invoking body from the init context.

Previously mentioned also in the FormData PR grafana/jslib.k6.io#21 (review).

import http from 'k6/http';
import { sleep } from 'k6';
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js';

export const options = {
  stages: [
    { duration: '30s', target: 50 },
  ],
};

const f = open('./1mb.bin', 'b');

export default function () {
  const fd = new FormData();
  fd.append('file', http.file(f, '1mb.bin'))
  fd.body()

  sleep(2);
}

The suggestion is to try to use directly a unique final TypedArray and the relative set method to make it more efficient (to be verified).
BTW, what will be decided in grafana/k6#2311 and the relative vision will impact for sure this issue so we have to keep them aligned.

FormData is broken as it expects the property "filename" to exist on an empty p.file

Ran into an issue with FormData producing the following error.

ERRO[0309] TypeError: Cannot read property 'filename' of undefined

I found this condition is accessing "filename" with out evaluating p.file even exists

if (p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

I had to update the condition to test for the existance of both.

// Check if p.file and p.file.filename exist before using if (p.file && p.file.filename) { cd += '; filename="' + p.file.filename.replace(/"/g,'%22') + '"'; }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.