-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUG#31606266 - SERVER HUNG WHILE CONFIGURING AFTER INSTALLING POSTFIX
Description =========== There is a race-condition between `event_base_loopbreak` and `event_base_loop`, when `loopbreak` is called before other thread enters `base_loop`, is such case all `breaks` and `exits` are ignored. The break function was not designed to be called from different thread. Fix === 1. Enable multithreading in `libevent`. 2. Switch from `event_base_loopbreak` to `event_base_loopexit`, where the last function, may be called from different thread. After enabling multithreading in libevent, the accepting speed (doc 19) decreases with following numbers: | Name | Baseline 20 | Document 19 | Change %| | Description | time[us] | time[us] | | |============================================|=============|=============|=========| | conn_plain<xclient_socket_nossl>/threads:1 | 425.3 | 453.9 | -6.3% | | conn_plain<xclient_socket_nossl>/threads:8 | 145.6 | 152.2 | -4.3% | | conn_plain<xclient_socket_nossl>/threads:16| 145.6 | 146.7 | -0.7% | | conn_plain<xclient_socket_nossl>/threads:32| 150.8 | 150.6 | 0.1% | RB: 24810 Reviewed by: Grzegorz Szwarc <grzegorz.szwarc@oracle.com> Reviewed-by: Tor Didriksen <tor.didriksen@oracle.com>
- Loading branch information
Showing
4 changed files
with
130 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License, version 2.0, | ||
as published by the Free Software Foundation. | ||
This program is also distributed with certain software (including | ||
but not limited to OpenSSL) that is licensed under separate terms, | ||
as designated in a particular file or component or in included license | ||
documentation. The authors of MySQL hereby grant you an additional | ||
permission to link the program and your derivative works with the | ||
separately licensed software that they have included with MySQL. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License, version 2.0, for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
#include <thread> | ||
|
||
#include "plugin/x/ngs/include/ngs/socket_events.h" | ||
|
||
namespace ngs { | ||
namespace test { | ||
|
||
class Socket_events_task_suite : public ::testing::Test { | ||
public: | ||
Socket_events m_sut; | ||
}; | ||
|
||
TEST_F(Socket_events_task_suite, loop_doesnt_block_when_no_events) { | ||
m_sut.loop(); | ||
} | ||
|
||
TEST_F(Socket_events_task_suite, execute_loop_until_no_events) { | ||
int execution_count = 4; | ||
m_sut.add_timer(10, [&execution_count]() { return --execution_count; }); | ||
m_sut.loop(); | ||
ASSERT_EQ(0, execution_count); | ||
} | ||
|
||
TEST_F(Socket_events_task_suite, | ||
break_loop_is_queued_and_ignores_active_events) { | ||
int execution_count = 0; | ||
|
||
m_sut.break_loop(); | ||
m_sut.add_timer(10, [&execution_count]() { | ||
++execution_count; | ||
return true; | ||
}); | ||
m_sut.loop(); | ||
ASSERT_EQ(0, execution_count); | ||
} | ||
|
||
TEST_F(Socket_events_task_suite, break_loop_from_thread) { | ||
std::atomic<int> execution_count; | ||
|
||
std::thread break_thread{[this, &execution_count]() { | ||
while (execution_count.load() < 10) { | ||
} | ||
m_sut.break_loop(); | ||
}}; | ||
|
||
m_sut.add_timer(10, [&execution_count]() { | ||
++execution_count; | ||
return true; | ||
}); | ||
m_sut.loop(); | ||
ASSERT_LT(0, execution_count.load()); | ||
break_thread.join(); | ||
} | ||
|
||
TEST_F(Socket_events_task_suite, break_loop_from_thread_always_active) { | ||
std::atomic<int> execution_count; | ||
|
||
std::thread break_thread{[this, &execution_count]() { | ||
while (execution_count.load() < 10) { | ||
} | ||
m_sut.break_loop(); | ||
}}; | ||
|
||
m_sut.add_timer(0, [&execution_count]() { | ||
++execution_count; | ||
std::this_thread::sleep_for(std::chrono::milliseconds(10)); | ||
return true; | ||
}); | ||
m_sut.loop(); | ||
ASSERT_LT(0, execution_count.load()); | ||
break_thread.join(); | ||
} | ||
|
||
} // namespace test | ||
} // namespace ngs |