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

Merge remote-tracking branch 'origin/release/0.8' into main #583

Merged
merged 9 commits into from
Oct 7, 2024
26 changes: 15 additions & 11 deletions common/test/test_throttle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ TEST(Throttle, try_consume) {
}

////////////////////////////////////////
#if defined(NDEBUG) && !defined(__APPLE__)
// The sleep and semaphore in macOS is less efficient and always cause variance, so skip macOS
#ifndef __APPLE__

struct FindAppropriateSliceNumSuite {
uint64_t slice_num;
Expand All @@ -177,6 +178,8 @@ class FindAppropriateSliceNumTest : public testing::TestWithParam<FindAppropriat
};

// More slices in a time window means sleep more frequently.
// In a fixed total time (10s), we measure how many IO were throttled (consumed),
// and compare to the dest amount, figure out the loss ratio brought by the throttler.
TEST_P(FindAppropriateSliceNumTest, run) {
const auto& p = GetParam();

Expand Down Expand Up @@ -251,7 +254,7 @@ class ThrottlePriorityTest : public testing::TestWithParam<PriorityTestSuite> {

INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
PriorityTestSuite{
// 0
// 0. Simulate same priority and equally divide the BW
PriorityTestSuite::Simulate,
100'000'000,
{50'000'000, 100'000, photon::throttle::Priority::High},
Expand All @@ -260,7 +263,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.4, 0.6,
},
PriorityTestSuite{
// 1
// 1. Simulate same priority but different BW, results are still the same
PriorityTestSuite::Simulate,
100'000'000,
{50'000'000, 1'000'000, photon::throttle::Priority::High},
Expand All @@ -269,7 +272,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.4, 0.6,
},
PriorityTestSuite{
// 2
// 2. Simulate different priorities with the same BW. Total BW exceeds limit
PriorityTestSuite::Simulate,
100'000'000,
{100'000'000, 500'000, photon::throttle::Priority::High},
Expand All @@ -278,7 +281,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.0, 0.1,
},
PriorityTestSuite{
// 3
// 3. Simulate different priorities with the same BW. Total BW under the limit
PriorityTestSuite::Simulate,
100'000'000,
{30'000'000, 1'000'000, photon::throttle::Priority::High},
Expand All @@ -287,7 +290,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.3, 0.7,
},
PriorityTestSuite{
// 4
// 4. Simulate different priorities with different BW. Total BW exceeds limit
PriorityTestSuite::Simulate,
100'000'000,
{50'000'000, 5'000'000, photon::throttle::Priority::High},
Expand All @@ -296,7 +299,8 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.45, 0.6,
},
PriorityTestSuite{
// 5. For now there is no way to balance throttle throughput of the same priority.
// 5. Real socket. For now there is no way to balance throttle throughput of the same priority.
// Maybe we need a WFQ in the future.
PriorityTestSuite::RealSocket,
1'000'000'000,
{1'000'000'000, 1048576, photon::throttle::Priority::High},
Expand All @@ -305,7 +309,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.0, 1.0,
},
PriorityTestSuite{
// 6
// 6. Real socket. High priority get most BW
PriorityTestSuite::RealSocket,
1'000'000'000,
{800'000'000, 32768, photon::throttle::Priority::High},
Expand All @@ -314,7 +318,7 @@ INSTANTIATE_TEST_P(Throttle, ThrottlePriorityTest, testing::Values(
0.1, 0.3,
},
PriorityTestSuite{
// 7
// 7. Real socket. Low priority gets the rest BW that high priority doesn't need
PriorityTestSuite::RealSocket,
10'000'000,
{5'000'000, 10'000, photon::throttle::Priority::High},
Expand Down Expand Up @@ -436,8 +440,8 @@ TEST_P(ThrottlePriorityTest, run) {
#endif

int main(int argc, char** argv) {
if (!photon::is_using_default_engine()) return 0;
photon::init(0, 0);
int ret = photon::init(photon::INIT_EVENT_DEFAULT, photon::INIT_IO_NONE);
if (ret) return -1;
DEFER(photon::fini());
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down
4 changes: 2 additions & 2 deletions common/throttle.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class throttle {
if (sem.count() * 100 < m_limit * fulfil_percent) {
// Request are fulfilled only if they saw enough percent of tokens,
// otherwise wait a `time_window_per_slice`.
ret = photon::thread_usleep(m_time_window_per_slice);
if (ret != 0) {
int sleep_ret = photon::thread_usleep(m_time_window_per_slice);
if (sleep_ret != 0) {
// Interrupted, just return
return -1;
}
Expand Down
Loading