Workforce: terminate after excessive idle cycles
- count each consecutive idle cycle - by default, terminate after 100 idle cycles (2 sec)
This commit is contained in:
parent
b493f15333
commit
dd62240900
3 changed files with 37 additions and 12 deletions
|
|
@ -42,6 +42,7 @@
|
|||
#include "lib/nocopy.hpp"
|
||||
//#include "lib/symbol.hpp"
|
||||
#include "lib/util.hpp"
|
||||
#include "lib/format-cout.hpp"////////////////////WIP
|
||||
|
||||
//#include <string>
|
||||
#include <utility>
|
||||
|
|
@ -108,6 +109,8 @@ namespace gear {
|
|||
break;
|
||||
if (res == activity::WAIT)
|
||||
res = idleWait();
|
||||
else
|
||||
idleCycles = 0;
|
||||
if (res != activity::PASS)
|
||||
break;
|
||||
}
|
||||
|
|
@ -120,10 +123,16 @@ namespace gear {
|
|||
activity::Proc
|
||||
idleWait()
|
||||
{
|
||||
std::this_thread::sleep_for (CONF::IDLE_WAIT);
|
||||
////////////////////////////////WIP extended inactivity detector here
|
||||
return activity::PASS;
|
||||
++idleCycles;
|
||||
if (idleCycles < CONF::DISMISS_CYCLES)
|
||||
{
|
||||
std::this_thread::sleep_for (CONF::IDLE_WAIT);
|
||||
return activity::PASS;
|
||||
}
|
||||
else // idle beyond threshold => terminate worker
|
||||
return activity::HALT;
|
||||
}
|
||||
size_t idleCycles{0};
|
||||
};
|
||||
}//(End)namespace work
|
||||
|
||||
|
|
|
|||
|
|
@ -197,8 +197,7 @@ namespace test {
|
|||
|
||||
|
||||
|
||||
/** @test TODO
|
||||
* @todo WIP 9/23 ⟶ define ⟶ implement
|
||||
/** @test a worker can be sent to sleep, reducing the poll frequency.
|
||||
*/
|
||||
void
|
||||
verify_workerSleep()
|
||||
|
|
@ -215,18 +214,34 @@ namespace test {
|
|||
sleep_for(10us);
|
||||
CHECK (1 == check);
|
||||
|
||||
sleep_for(10ms); // after waiting one sleep-period...
|
||||
sleep_for(12ms); // after waiting one sleep-period...
|
||||
CHECK (2 == check); // ...functor invoked again
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test TODO
|
||||
* @todo WIP 9/23 ⟶ define ⟶ implement
|
||||
/** @test when a worker is sent into sleep-cycles for an extended time,
|
||||
* the worker terminates itself
|
||||
*/
|
||||
void
|
||||
verify_workerDismiss()
|
||||
{
|
||||
atomic<uint> check{0};
|
||||
WorkForce wof{setup ([&]{ ++check; return activity::WAIT; })
|
||||
.withSleepPeriod (10ms)
|
||||
.dismissAfter(5)};
|
||||
|
||||
wof.incScale();
|
||||
sleep_for(20us);
|
||||
|
||||
CHECK (1 == check);
|
||||
|
||||
sleep_for(10ms);
|
||||
CHECK (2 == check); // after one wait cycle, one further invocation
|
||||
|
||||
sleep_for(100ms);
|
||||
CHECK (5 == check); // only 5 invocations total...
|
||||
CHECK (0 == wof.size()); // ...after that, the worker terminated
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -293,7 +308,7 @@ namespace test {
|
|||
atomic<uint> check{0};
|
||||
WorkForce wof{setup ([&]{
|
||||
++check;
|
||||
if (check == 10'000 or check == 10'110)
|
||||
if (check == 5'000 or check == 5'110)
|
||||
return activity::HALT;
|
||||
else
|
||||
return activity::PASS;
|
||||
|
|
@ -308,7 +323,8 @@ namespace test {
|
|||
|
||||
CHECK (3 == wof.size());
|
||||
|
||||
sleep_for(200ms); // ...sufficiently long to count way beyond 10'000
|
||||
sleep_for(500ms); // ...sufficiently long to count way beyond 10'000
|
||||
CHECK (check > 6'000);
|
||||
CHECK (1 == wof.size());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80047,8 +80047,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#338800" CREATED="1694098789389" ID="ID_1077314922" MODIFIED="1694212909443" TEXT="verify_workerSleep: schläft auf Anweisung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1694098829216" ID="ID_358493866" MODIFIED="1694210792272" TEXT="verify_workerDismiss: terminiert nach längerem Schlaf">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node COLOR="#338800" CREATED="1694098829216" ID="ID_358493866" MODIFIED="1694216676875" TEXT="verify_workerDismiss: terminiert nach längerem Schlaf">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1694212971758" ID="ID_321316770" MODIFIED="1694212980437" TEXT="brauche Konfigurierbarkeit für Test"/>
|
||||
<node CREATED="1694212996114" ID="ID_279149518" MODIFIED="1694213012580" TEXT="...denn im Realbetrieb wird man länger warten"/>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue