-
Notifications
You must be signed in to change notification settings - Fork 481
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
logqueue-disk: serialize outside of the lock in the source threads #3746
logqueue-disk: serialize outside of the lock in the source threads #3746
Conversation
Could you share the measurement, please? As far as I remember, it was a 60% improvement in general when the reliable disk-buffer was used. The non-reliable disk-buffer has some qout/qoverflow move logic that slows us down, we're investigating that one separately.
I think we could add a NEWS entry about the overall performance improvement in the last pull request. I'm sharing two flame graphs, which show the ratios between the actual disk writes and the serialization/deserialization logic: |
Build SUCCESS |
Sure, let me measure everything again tomorrow. Thanks! |
316c17d
to
5b1294a
Compare
Build FAILURE |
5b1294a
to
350b91a
Compare
Build SUCCESS |
acaef7f
to
a028825
Compare
Build SUCCESS |
Added the hint for needing serialized message. |
@kira-syslogng do stresstest |
Build SUCCESS |
Kira-stress-test: Build SUCCESS |
modules/diskq/logqueue-disk.c
Outdated
gboolean consumed = FALSE; | ||
|
||
if (qdisk_started(self->qdisk) && qdisk_is_space_avail(self->qdisk, 64)) | ||
{ | ||
ScratchBuffersMarker marker; | ||
GString *write_serialized = scratch_buffers_alloc_and_mark(&marker); | ||
|
||
sa = serialize_string_archive_new(write_serialized); | ||
log_msg_serialize(msg, sa, options->compaction ? LMSF_COMPACTION : 0); | ||
if (!qdisk_serialize_msg(self->qdisk, msg, write_serialized)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
qdisk: move serialization to qdisk
is not only a move (refactor) commit, you also fixed the error handling of log_msg_serialize()
.
Signed-off-by: Attila Szakacs <[email protected]>
3718a0f
to
1c9060c
Compare
@MrAnno Thanks, I implemented your suggestion. The old implementation is available at: https://github.com/alltilla/syslog-ng/commits/diskq-perf-serialize-outside-lock-orig if for some reason it will be needed. |
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
…ll() Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
1c9060c
to
92110da
Compare
Build SUCCESS |
@kira-syslogng do stresstest |
Kira-stress-test: Build SUCCESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the refactor was a really good direction. Now that locks are closer to the actual implementation, we already see additional places where those locks are not necessary.
A few lines of code duplication was added as a result of the refactor/inheritance fix, but further refactor rounds will be much easier upon this work than on the original code IMHO.
I think only one of my notes should be fixed in this PR (the accidental change of the disk-buffer file's magic numbers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this version has the same performance figures as the previous proposed change ?
Have you measured that only the refactor part had any performance difference ?
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
Just for the sake of symmetry. Signed-off-by: Attila Szakacs <[email protected]>
The serialized message now already has the guint32 record length in its beginning, so we do not need to make an adjustment in is_space_avail(). There are 2 other places where qdisk_is_space_avail() is used: * LogQueueDiskNonReliable::_has_movable_message(): It is a guess with a relatively high size, so we do not need to adjust it. * LogQueueDisk::log_queue_disk_write_message(): It will be fixed in one of the following commits. Signed-off-by: Attila Szakacs <[email protected]>
This functions does 3 things: 1. Does some preliminary check on QDisk. 2. Serializes the message. 3. Writes the message to the QDisk. Serializing and writing to disk are expensive actions. We are doing both, while holding the LogQueue::lock. We do not need to hold the lock while serializing. In order to move the serialization outside the lock, we need more control, which cannot be done with this common function. This commit only moves the function to the descendant classes, we will implement our class specific behavior in the following commits. Signed-off-by: Attila Szakacs <[email protected]>
…il() This commit also fixes the available space checking, mentioned in a169e331. Signed-off-by: Attila Szakacs <[email protected]>
…message_to_disk() The free space is checked in qdisk_push_tail(), it is unnecessary to do it twice. Signed-off-by: Attila Szakacs <[email protected]>
Signed-off-by: Attila Szakacs <[email protected]>
…h_tail() Signed-off-by: Attila Szakacs <[email protected]>
92110da
to
a80ef51
Compare
Yes.
No, I can do so, if you would like me to. |
Build SUCCESS |
@kira-syslogng do stresstest |
Kira-stress-test: Build SUCCESS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Not needed, I was just curios if we have the data. |
It is common to have multiple source threads.
When we use disk-buffer, the message's serialization and writing it to the disk happen in the source thread.
Currently, the serialization happens while the source thread is holding the
LogQueue
's lock. Also it is inbetween two accesses of theQDisk
.If we just simply move the serialization outside the lock, we are not guaranteed to have the same
QDisk
state, as we were having beforehand, so it is better to move the whole serialization betweenQDisk
is ever accessed and the lock is obtained.This can yield significant performance improvement, because while the source threads are doing their slow serialization, the destination thread can process messages from the
QDisk
. In my local measurements, this change introduced a 40-50% performance gain compared to syslog-ng-3.32.1.No news file needed, IMO.
Signed-off-by: Attila Szakacs [email protected]