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

rate example #17

Merged
merged 1 commit into from
Mar 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions example/nebula-test-insert-limit-rate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// refer https://k6.io/blog/how-to-generate-a-constant-request-rate-with-the-new-scenarios-api/
// the example options means:
// 1. each second, 1000 iterations would be made.
// 2. max concurrent vu is 300.
// 3. last 30 seconds, so it would run 1000*30 = 30000 iterations.
// 4. batchSize is 1, so it would insert one recond per iteration.
import nebulaPool from 'k6/x/nebulagraph';
import { check } from 'k6';
import { Trend } from 'k6/metrics';
import { sleep } from 'k6';

var lantencyTrend = new Trend('latency');
var responseTrend = new Trend('responseTime');
// initial nebula connect pool
var pool = nebulaPool.initWithSize("192.168.8.61:9669,192.168.8.62:9669,192.168.8.63:9669", 400, 4000);

// set csv strategy, 1 means each vu has a separate csv reader.
pool.configCsvStrategy(1)

// initial session for every vu
var session = pool.getSession("root", "nebula")
session.execute("USE ldbc")

// concurrent 300, and each second, 1000 iterations would be made.
export const options = {
scenarios: {
constant_request_rate: {
executor: 'constant-arrival-rate',
rate: 1000,
timeUnit: '1s',
duration: '30s',
preAllocatedVUs: 300,
maxVUs: 300,
},
},
};

export function setup() {
// config csv file
pool.configCSV("person.csv", "|", false)
// config output file, save every query information
pool.configOutput("output.csv")
sleep(1)
}

export default function (data) {
// get csv data from csv file
let ngql = 'INSERT VERTEX Person(firstName, lastName, gender, birthday, creationDate, locationIP, browserUsed) VALUES '
let batches = []
let batchSize = 1
// batch size
for (let i = 0; i < batchSize; i++) {
let d = session.getData();
let values = []
// concat the insert value
for (let index = 1; index < 8; index++) {
let value = '"' + d[index] + '"'
values.push(value)
}
let batch = d[0] + ":(" + values.join(",") + ")"
batches.push(batch)
}
ngql = ngql + batches.join(',')
let response = session.execute(ngql)
check(response, {
"IsSucceed": (r) => r.isSucceed() === true
});
// add trend
lantencyTrend.add(response.getLatency());
responseTrend.add(response.getResponseTime());

};

export function teardown() {
pool.close()
}