Skip to content

Commit

Permalink
feat: Added option for parallel processing of replay ingestion (#17585)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjackwhite authored Sep 25, 2023
1 parent 1adf09a commit d9388ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions plugin-server/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ export function getDefaultConfig(): PluginsServerConfig {
SESSION_RECORDING_REMOTE_FOLDER: 'session_recordings',
SESSION_RECORDING_REDIS_PREFIX: '@posthog/replay/',
SESSION_RECORDING_PARTITION_REVOKE_OPTIMIZATION: false,
SESSION_RECORDING_PARALLEL_CONSUMPTION: false,
POSTHOG_SESSION_RECORDING_REDIS_HOST: undefined,
POSTHOG_SESSION_RECORDING_REDIS_PORT: undefined,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ export class SessionRecordingIngesterV2 {
statsKey: `recordingingester.handleEachBatch`,
logExecutionTime: true,
func: async () => {
const transaction = Sentry.startTransaction({ name: `blobIngestion_handleEachBatch` }, {})
histogramKafkaBatchSize.observe(messages.length)

const recordingMessages: IncomingRecordingMessage[] = []
Expand Down Expand Up @@ -385,16 +384,14 @@ export class SessionRecordingIngesterV2 {
})

await runInstrumentedFunction({
statsKey: `recordingingester.handleEachBatch.consumeSerial`,
statsKey: `recordingingester.handleEachBatch.consumeBatch`,
func: async () => {
for (const message of recordingMessages) {
const consumeSpan = transaction?.startChild({
op: 'blobConsume',
})

await this.consume(message, consumeSpan)
// TODO: We could do this as batch of offsets for the whole lot...
consumeSpan?.finish()
if (this.serverConfig.SESSION_RECORDING_PARALLEL_CONSUMPTION) {
await Promise.all(recordingMessages.map((x) => this.consume(x)))
} else {
for (const message of recordingMessages) {
await this.consume(message)
}
}
},
})
Expand All @@ -417,8 +414,6 @@ export class SessionRecordingIngesterV2 {
await this.flushAllReadySessions()
},
})

transaction.finish()
},
})
}
Expand Down Expand Up @@ -544,7 +539,9 @@ export class SessionRecordingIngesterV2 {
this.partitionAssignments[topicPartition.partition] = {}
})

await this.partitionLocker.claim(topicPartitions)
if (this.serverConfig.SESSION_RECORDING_PARTITION_REVOKE_OPTIMIZATION) {
await this.partitionLocker.claim(topicPartitions)
}
await this.offsetsRefresher.refresh()
}

Expand Down
1 change: 1 addition & 0 deletions plugin-server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export interface PluginsServerConfig {
SESSION_RECORDING_REMOTE_FOLDER: string
SESSION_RECORDING_REDIS_PREFIX: string
SESSION_RECORDING_PARTITION_REVOKE_OPTIMIZATION: boolean
SESSION_RECORDING_PARALLEL_CONSUMPTION: boolean

// Dedicated infra values
SESSION_RECORDING_KAFKA_HOSTS: string | undefined
Expand Down

0 comments on commit d9388ad

Please sign in to comment.