Skip to content

Asynchronously send alerts  #1285

@starsdeep

Description

@starsdeep

@brancz

cc @brian-brazil

We currently send alerts at every eval interval, and we sent alerts synchronously, see https://github.com/prometheus/alertmanager/blob/master/dispatch/dispatch.go#L371-L373, so when the reader read alerts from channel, it will not continue to read next alert until it successfully send the alert to all kinds of clients. And as we all know sending alert message to clients involve networking, which is slow. So, consumer can not catch up with producer, thus the channel will saturate.

Then, I propose to send alerts asynchronously:

// current synchronous code at https://github.com/prometheus/alertmanager/blob/master/dispatch/dispatch.go#L371-L373
ag.flush(func(alerts ...*types.Alert) bool {
	return nf(ctx, alerts...)
})

// asynchronous code I propose:
go func() {
	ag.flush(func(alerts ...*types.Alert) bool {
		return nf(ctx, alerts...)
	})
}()

With this simple optimization, the runtime.mach_semaphore_signal time can decrease from 33.3% to 16.6%

profile for current synchronous code
image

profile for asynchronous code I proposed:
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions