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

perf(ingestion): process overflow redirect in parallel of other events #17805

Merged
merged 2 commits into from
Oct 9, 2023
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ export async function eachBatchParallelIngestion(
.observe(splitBatch.toProcess.length)
kafkaBatchStart.inc() // just before processing any events
const tasks = [...Array(parallelism)].map(() => processMicroBatches(splitBatch.toProcess))
await Promise.all(tasks)

// Process overflow after the main batch is successful to reduce the risk of duplicates
// generated by batch retries. Delay ACKs into processingPromises too.
/**
* Process overflow redirection while the micro-batches move forward.
* This increases throughput at the risk of duplication if the batch fails and retries.
*/
if (splitBatch.toOverflow.length > 0) {
const overflowSpan = transaction.startChild({
op: 'emitToOverflow',
Expand All @@ -200,6 +201,8 @@ export async function eachBatchParallelIngestion(
overflowSpan.finish()
}

await Promise.all(tasks)

// Await on successful Kafka writes before closing the batch. At this point, messages
// have been successfully queued in the producer, only broker / network failures could
// impact the success. Delaying ACKs allows the producer to write in big batches for
Expand Down Expand Up @@ -264,7 +267,7 @@ async function emitToOverflow(queue: IngestionConsumer, kafkaMessages: Message[]
queue.pluginsServer.kafkaProducer.produce({
topic: KAFKA_EVENTS_PLUGIN_INGESTION_OVERFLOW,
value: message.value,
key: message.key,
key: undefined, // No locality guarantees in overflow
headers: message.headers,
waitForAck: true,
})
Expand Down