Skip to content

Instantly share code, notes, and snippets.

@aheld
Created December 30, 2022 14:56
Show Gist options
  • Save aheld/41e55ae074be1102b22a27f9c72c30b3 to your computer and use it in GitHub Desktop.
Save aheld/41e55ae074be1102b22a27f9c72c30b3 to your computer and use it in GitHub Desktop.
const { EventHubProducerClient } = require("@azure/event-hubs")
const { chunkPromise, PromiseFlavor } = require('chunk-promise')
var now = require("performance-now")
var sp = require('streaming-percentiles')
var epsilon = 0.1;
var g = new sp.GK(epsilon);
const TestCases = require("../events/test_cases.js")
const impression = TestCases[0].expected.outputClientImpressionMessage[0]
const connectionString=process.env.connectionString
const eventHubName="loadtest"
async function publish() {
const producerClient = new EventHubProducerClient(connectionString, eventHubName)
for (x=1; x < 100; x++){
const eventDataBatch = await producerClient.createBatch();
let numberOfEventsToSend = 2;
while (numberOfEventsToSend > 0) {
let wasAdded = eventDataBatch.tryAdd({ body: impression });
if (!wasAdded) {
break;
}
numberOfEventsToSend--;
}
const start = now()
await producerClient.sendBatch(eventDataBatch)
g.insert(now() - start)
}
producerClient.close()
}
async function publishBatches(){
promiseArr = []
total = 1
for (index = 0; index < total; index++) {
promiseArr.push(async () => {
await publish()
})
}
total = total * 100
console.log("Start Writing " + total + " records")
const runstart = now()
await chunkPromise(promiseArr, {
concurrent:1,
promiseFlavor: PromiseFlavor.PromiseAll
})
const runend = now()
console.log("run time: ", Math.floor((runend - runstart)/1000), " Seconds")
console.log("req/sec:" , Math.floor(total / ((runend - runstart)/1000)))
var p50 = g.quantile(0.5); // Approx. median
var p95 = g.quantile(0.95); // Approx. 95th percentile
console.log("p50: ", Math.floor(p50), "ms")
console.log("p95: ", Math.floor(p95), "ms")
}
publishBatches()
// .then(() => producerClient.close())
.then(()=>console.log("Done"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment