Grafana k6
Grafana k6 is an open-source load testing tool to simplify and automate performance testing of your APIs and – when combined with Modzy – your AI/ML models, to help you to build resilient and performant models that scale. With k6 you can test the reliability and performance of your AI/ML models and systems and catch performance regressions and problems with each version, retraining or flow change. k6 allows you easily to smoke test, load and stress test, and soak test your models – alone or as part of an A/B competition.
Examples
Modzy's RESTful APIs are easily triggered with k6. Here are a couple example scripts for adding text and binary or image data jobs.
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
vus: 3,
duration: '10s',
};
export default function () {
const url = 'https://trial.app.modzy.com/api/jobs';
const payload = JSON.stringify({
model: {
identifier: "ed542963de",
version: "1.0.1",
},
input: {
type: "text",
sources: {
"my-input": {
"input.txt": "Lorem ipsum dolor sit amet"
},
},
},
});
const params = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey <INSERT YOUR API KEY HERE>',
},
};
http.post(url, payload, params);
sleep(1);
}
import http from 'k6/http';
import { sleep } from 'k6';
import encoding from 'k6/encoding';
export const options = {
vus: 3,
duration: '10s',
};
const imageFile = open('path/to/image.jpg', 'b');
export default function () {
const url = 'https://trial.app.modzy.com/api/jobs';
const payload = JSON.stringify({
model: {
identifier: "b65cb23c29",
version: "1.1.1",
},
input: {
type: "embedded",
sources: {
"my-input": {
"image": "data:image/jpeg;base64,"+encoding.b64encode(imageFile),
},
},
},
});
const params = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey <INSERT YOUR API KEY HERE>',
},
};
http.post(url, payload, params);
sleep(1);
}
For batch operations of multiple models, multiple versions, or multiple inference jobs, use k6's batch features:
import http from 'k6/http';
import { sleep } from 'k6';
import { check } from 'k6';
import encoding from 'k6/encoding';
export const options = {
vus: 1,
duration: '1s',
};
const API_URL = 'https://trial.app.modzy.com/api';
const API_KEY = '<INSERT YOUR API KEY HERE>';
const van_img = open('path/to/image.jpg', 'b');
const chi_img = open('path/to/image2.jpg', 'b');
const ocr_img = open('path/to/image3.jpg', 'b');
const ocr_config = open('path/to/config.json', 'b');
export default function () {
const url = API_URL+'/jobs';
const params = {
headers: {
'Content-Type': 'application/json',
'Authorization': 'ApiKey '+API_KEY,
},
};
const sa_payload = JSON.stringify({
model: { identifier: "ed542963de", version: "1.0.1", },
input: {
type: "text",
sources: {
"my-input": {
"input.txt": "Lorem ipsum dolor sit amet"
},
},
},
});
const img_payload = JSON.stringify({
model: {
identifier: "b65cb23c29",
version: "1.1.1",
},
input: {
type: "embedded",
sources: {
"my-input": {
"image": "data:image/jpeg;base64,"+encoding.b64encode(van_img),
},
},
},
});
const geolo_payload = JSON.stringify({
model: {
identifier: "ldxedidrdd",
version: "1.0.1",
},
input: {
type: "embedded",
sources: {
"my-input": {
"image": "data:image/jpeg;base64,"+encoding.b64encode(chi_img),
},
},
},
});
const ocr_payload = JSON.stringify({
model: {
identifier: "c60c8dbd79",
version: "0.0.2",
},
input: {
type: "embedded",
sources: {
"my-input": {
"input": "data:image/jpeg;base64,"+encoding.b64encode(ocr_img),
"config.json": "data:application/json;base64,"+encoding.b64encode(ocr_config),
},
},
},
});
const responses = http.batch([
['POST', url, sa_payload, params],
['POST', url, img_payload, params],
['POST', url, geolo_payload, params],
['POST', url, ocr_payload, params],
]);
check(responses[0], {
'main page status was 202': (res) => res.status === 202,
});
sleep(1);
}
Updated about 1 year ago