perf: make basicPublish sync#80
Merged
Merged
Conversation
Owner
|
I can imagine how this might help, but I'd love to see some numbers |
Contributor
Author
|
So here is the methodology what I came up with as I have no idea whether there is a proper tool for it. The scriptimport { randomUUID } from 'crypto';
import { Connection } from './src/Connection';
import { PerformanceObserver } from 'perf_hooks';
const counter = new Map<number, { duration: number, times: number }>();
const observer = new PerformanceObserver((list) => {
list.getEntries().forEach((entry) => {
const detail = entry.detail as Record<string, unknown>;
if ("kind" in detail && typeof detail.kind === "number") {
const existing = counter.get(detail.kind);
if (existing) {
existing.duration += entry.duration;
existing.times += 1;
} else {
counter.set(detail.kind, { duration: entry.duration, times: 1 });
}
}
});
});
observer.observe({ buffered: false, entryTypes: ['gc'] });
async function run() {
const queue = randomUUID();
const payload = Buffer.from('prometheus')
const connection = new Connection("amqp://guest:guest@localhost:5672");
const pub = await connection.acquire();
await pub.queueDeclare(queue);
global.gc!();
for (let i = 0; i < 1_000_000; i++) {
await pub.basicPublish(queue, payload);
}
await pub.close();
await connection.close();
global.gc!();
}
run().then(() => {
observer.disconnect();
const entries = Array.from(counter.entries()).sort((a, b) => a[0] - b[0]);
for (const [kind, { duration, times }] of entries) {
console.log(`Kind: ${kind}, Duration: ${duration.toFixed(2)}ms, Times: ${times}`);
}
});Old results:New resultsConclusionSeems that there are less GC pauses |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In theory this should reduce memory traffic for an application that does a lot of publishing without confirm mode. Not sure about real world impact though, but for one of our most producing applications we had small benefit in memory usage from moving from Publisher to Channel, basically the difference there in one additional Promise to what I can see.