FormData high CPU usage
codebien opened this issue · 1 comments
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.
I encountered this issue, was heavily CPU bound for a test with a rather small image involved, write up and workaround here: grafana/k6#3888
Hope this helps anyone that comes across this.