Commit graph

6271 commits

Author SHA1 Message Date
d622b59dfd Scheduler: support for classification data in Layer-1
- this is prerequisite to check for significance of the head entry
- implement and verify the information functions at Layer-1
2023-11-02 23:25:44 +01:00
7887941c89 Scheduler: prepare for dropping obsoleted entries
...it is clear that there must be a way to flush the scheduler queues
an thereby silently drop any obsoleted or irrelevant entries. This topic
turns out to be somewhat involved, as it requires to consider the
deadline (due to the memory management, which is based on deadlines).
Furthermore there is a relation to yet another challenging conceptual
requirement, which is the support for other operation modes beyond
just time-bound rendering; these concerns make it desirable to
expand the internal representation of entries in the queue.

Concerns regarding performance are postponed deliberately,
until we can demonstrate the Scheduler-Service running under
regular operational conditions.
2023-11-02 16:46:08 +01:00
5c5dc40f3f Scheduler: processing of peak loads works
This is the first kind of integration,
albeit still with a synthetic load.

- placed two excessive load peaks in the scheduling timeline
- verified load behaviour
- verified timings
- verified that the scheduler shuts down automatically when done
2023-11-01 04:24:44 +01:00
4937577557 (WIP) instrumentation for investigation of sleep-behaviour 2023-11-01 02:06:02 +01:00
9f7711d26b Scheduler: complete and cover load indicator
- sample distance to scheduler head whenever a worker asks for work
- moving average with N = worker-pool size and damp-factor 2
- multiply with the current concurrency fraction
2023-10-31 02:29:50 +01:00
a087e52ab1 Scheduler: draft a load indicator
...using a state fusion
based on both the threadpool size and the average distance
or lag to the next task to be scheduled.
2023-10-30 20:22:06 +01:00
6a7a2832bf Scheduler: simplify usage of microbenchmark helper
as an aside, the header lib/test/microbenchmark.hpp
turns out to be prolific for this kind of investigation.

However, it is somewhat obnoxious that the »test subject«
must expose the signature <size_t(size_t)>.

Thus, with some metaprogramming magic, an generic adaptor
can be built to accept a range of typical alternatives,
and even the quite obvious signature void(void).
Since all these will be wrapped directly into a lambda,
the optimiser will remove these adaptations altogether.
2023-10-30 20:17:16 +01:00
4fada4225c Scheduler: watch behaviour under load
- create a synthetic load peak while operating with full WorkForce
- Goal is to develop a load indicator
2023-10-30 05:09:41 +01:00
22b4a9e4b2 Scheduler: start and shutdown implemented and demonstrated in test
- An important step towards a complete »Scheduler Service«
- Correct timing pattern could be verified in detail by tracing
- Spurred some further concept and design work regarding Load-control
2023-10-29 20:06:41 +01:00
8505059476 Scheduler: consider how to maintain active state
- draft the duty cycle »tick«
- investigate corner cases of state updates and allocation managment
- implement start and forcible stop of the scheduler service
2023-10-29 04:22:42 +01:00
4e9d54e6f9 Scheduler: switch to steady-clock
Obviously the better choice and a perfect fit for our requirements;
while the system-clock may jump and even move backwards on time service
adjustments, the steady clock just counts the ticks since last boot.

In libStdC++ both are implemented as int64_t and use nanoseconds resolution
2023-10-28 20:58:37 +02:00
6166ab63f2 Scheduler: complete handling of the grooming-token
- Ensure the grooming-token (lock) is reliably dropped
- also explicitly drop it prior to trageted sleeps
- properly signal when not able to acquire the token before dispatch

- amend tests broken by changes since yesterday
2023-10-28 05:35:35 +02:00
552d8dec0e Scheduler: complete work-Function / conception work
Notably the work-function is now completely covered, by adding
this last test, and the detailed investigations yesterday
ultimately unveiled nothing of concern; the times sum up.

Further reflection regarding the overall concept led me
to a surprising solution for the problem with priority classes.
2023-10-28 05:34:56 +02:00
e26d251867 Scheduler: rationalise delay decision logic
...especially for the case »outgoing to sleep«

- reorganise switch-case to avoid falling through
- properly handle the tendedNext() predicate also in boundrary cases
- structure the decision logic clearer
- cover the new behaviour in test

Remark: when the queue falls empty, the scheduler now sends each
worker once into a targted re-shuffling delay, to ensure the
sleep-cycles are statistically evenly spaced
2023-10-28 05:34:56 +02:00
b5e9d67a79 Scheduler: wrap-up and comment test cases thus far
...up to now, Behaviour is as expected
- with some minor discrepancies still to be fixed
- and an effect due to the test-scaffolding
2023-10-27 03:37:24 +02:00
097001d16f Scheduler: investigate timings of dispatch()
...there seemed to be an anomaly of 50...100µs

==> conclusion: this is due to the instrumentation code
    - it largely caused by the EventLog, which was never meant
      to be used in performance-critical code, and does hefty
      heap allocations and string processing.
    - moreover, there clearly is a cache-effect, adding a Factor 2
      whenever some time passed since the last EventLog call

==> can be considered just an artifact of the test setup and
    will have no impact on the scheduler


remark: this commit adds a lot of instrumentation code
2023-10-27 02:53:34 +02:00
a90a5d9636 Scheduler: can demonstrate basic behaviour
- invoked right away
- pre-sleep to tend next
- post-sleep if next activity follows at a distance
2023-10-26 03:56:18 +02:00
a71bcaae43 Scheduler: shorthand notation for work-Function test
To cover the visible behaviour of the work-Function,
we have to check an amalgam of timing delays and time differences.

This kind of test tends to be problematic, since timings are always
random and also machine dependent, and thus we need to produce pronounced effects
2023-10-26 01:14:13 +02:00
5164ead929 Scheduler: access invocation time for test
...find a way to sneak out the "now" parameter passed on Invocation
...this is prerequisite to demonstrate expected behaviour of the work-Function
2023-10-25 23:40:47 +02:00
7da88b772f Scheduler: setup to verify the work-Function
...first steps to get anything to run with the Scheduler constructed thus far
...can now
 - enqueue
 - getWork -> invoke
2023-10-25 17:31:32 +02:00
a180d38ed9 Scheduler: integrate capacity handling with work-Function
...this integration becomes more and more challenging
...the high degree of inter-correlation between the scheduler components is concerning
2023-10-25 05:11:10 +02:00
d6c859fd3a Scheduler: implement and document capacity redirection 2023-10-25 02:13:18 +02:00
1d5b8c3e9c Scheduler: implement and verify random reshuffling of capacity
...using the current time itself as source for randomisation;
the test indicates this yields a smooth and even distribution.
2023-10-24 04:59:49 +02:00
3eaf623e98 Scheduler: develop scheme for capacity redirection
...to make that abundantly clear: we do not aim at precision timing,
rather the goal is to redistribute capacity currently not usable...

Basically we're telling the worker "nothing to do right now, sorry,
but check back in <timespan> because I may need you then"
2023-10-24 00:56:24 +02:00
08c13ed6fe Scheduler: consider wiring of Load-Controller
...and general questions of component design and coupling.
Decided to go for explicit configuration points by functor.
2023-10-23 21:51:16 +02:00
69fb77246e Scheduler: implement capacity redistribution scheme
wow... that was conceptually challenging, yet dead easy to implement
2023-10-23 18:48:02 +02:00
6ccb6540e6 Scheduler: implement the tended-next mark
...as KISS solution to put aside the next free capacity
whenever a new time point appears at scheduler head
2023-10-23 17:02:44 +02:00
84ca2460c1 Scheduler: fundamentals of capacity classification
Workers asking for the next task are classified as belonging
to some fraction of the free capacity, based on the distance
to the closest next Activity known to the scheduler
2023-10-23 04:07:38 +02:00
b61ca94ee5 Scheduler: rectify λ-post API
...to bring it more in line with all the other calls dealing with Activity*
...allows also to harmonise the ActivityLang::dispatchChain()
...and to compose the calls in Scheduler directly

NOTE: there is a twist: our string-formatting helper did not render
custom string conversions for objects passed as pointer. This was a
long standing problem, caused by ambiguous templates overloads;
now I've attempted to solve it one level more down, in util::StringConv.
This solution may turn out brittle, since we need to exclude any direct
string conversion, most notably the ones for C-Strings (const char*)

In case this solution turns out unsustainable, please feel free
to revert this API change, and return to passing Activity& in λ-post,
because in the end this is cosmetics.
2023-10-23 01:48:46 +02:00
a21057bdf2 Scheduler: control structure for the worker-functor 2023-10-22 23:25:35 +02:00
e5638119f5 Scheduler: devise scheme for load control
- organise by principles rather than implementing a mechanism
- keep the first version simple yet flexible
- conduct empiric research under synthetic load

Basic scheme:
- tend for next
- classify free capacity
- scattered targeted wait
2023-10-22 16:45:13 +02:00
ccf970eaee Scheduler: clarify redundant λ-post param
The signature for the »post« operation includes the ExecutionCtx itself,
which is obviously redundant, given that this operation is ''part of this context.''

However, for mock-implementation of the ExecutionCtx for unit testing,
the form of the implementation was deliberately kept unspecified, allowing
to use functor objects, which can be instrumented later. Yet a functor
stored as member has typically no access to the "this"-ptr...
2023-10-22 01:56:22 +02:00
d67c62b02f Scheduler: solve difficulties with member function signature
The approach to provide the ExecutionCtx seems to work out well;
after some investigation I found a solution how to code a generic
signature-check for "any kind of function-like member"...

(the trick is to pass a pointer or member-pointer, which happens
to be syntactically the same and can be handled with our existing
function signature helper after some minor tweaks)
2023-10-22 00:42:57 +02:00
0d2d8c3413 Scheduler: providing the execution-context
The Activity-Language can be defined by abstracting away
some crucial implementation functionality as part of an generic
»ExecutionCtx«, which in the end will be provided by the Scheduler.

But how actually?
We want to avoid unnecessary indirections, and ideally we also want
a concise formulation in-code. Here I'm exploring the idea to let the
scheduler itself provide the ExecutionCtx-operations as member functions,
employing some kind of "compile-time duck-typing"

This seems to work, but breaks the poor-man's preliminary "Concept" check...
2023-10-21 03:01:27 +02:00
26b2e6f1bd Scheduler: solve the initialisation of WorkForce
Notably I wanted an entirely static and direct binding
to the internals of the Scheduler, which can be completely inlined.
The chosen solution also has the benefit of making the back-reference
to the Scheduler explicitly visible to the reader. This is relevant,
since the Config-Subobject is *copied* into each Worker instance.
2023-10-20 18:24:50 +02:00
74c97614b3 Scheduler: component wiring
The »Scheduler Service« will be assembled
from the components developed during the last months
- Layer-1
- Layer-2
- Activity-Language
- Block-Flow
- Work-Force
2023-10-20 04:36:07 +02:00
9db341bd8b Scheduler: plan for integration
identified three distinct tasks
- build the external API
- establish component integration
- performance testing
2023-10-20 00:59:50 +02:00
9ce3ad3d72 Scheduler: Layer-2 complete and tested (see #1326)
* the implementation logic of the Scheduler is essentially complete now
 * all functionality necessary for the worker-function has been demonstrated

As next step, the »Scheduler Service« can be assembled from the two
Implementation Layers, the Activity-Language and the `BlockFlow` allocator
This should then be verified by a multi-threaded integration test...
2023-10-19 01:49:08 +02:00
10a2c6908c Scheduler: Layer-2 integration scenario complete
could even rig the diagnostic Execution-Ctx
to drop the GroomingToken at the point when switching to work-mode
2023-10-18 23:02:29 +02:00
c2ddaed28e Scheduler: draft scenario for Layer-2 integration test
Idea: re-use the scenario and instrumentation from
SchedulerActivity_test::scenario_RenderJob()
2023-10-18 18:10:10 +02:00
ee09a2eff2 Scheduler: completed implementation of Layer-2
...some further checks
...one integration test case needs to be written
2023-10-18 17:29:41 +02:00
93fcebb331 Scheduler: implement and verify postDispatch 2023-10-18 16:39:08 +02:00
666546856f Scheduler: design the core API operation - postDispatch
This central operation sits at a crossroad and is used
- from external clients to fed new work to the Scheduler
- from Workers to engage into execution of the next Activity
- recursively from the execution of an Activity-chain

From these requirements the semantics of behaviour can be derived
regarding the GroomingToken and the result values, which indicate
when follow-up work should be processed
2023-10-18 15:50:11 +02:00
55967cd649 Scheduler: work retrieval implementation
- simple approach, delegating to Layer-1
- deliberately no error handling
- GroomingToken not dropped
2023-10-18 04:18:01 +02:00
b57503fb97 Scheduler: define expected behaviour for work retrieval
still not quite sure how to implement it,
but working down from first principles to define test scenarios first...
2023-10-18 02:59:58 +02:00
aa60869082 Scheduler: decision logic for actual dispatch of activities 2023-10-18 01:38:58 +02:00
fa391d1267 Scheduler: torture test the thread access logic
Ensure the GroomingToken mechanism indeed creates an
exclusive section protected against concurrent corruption:

Use a without / with-protection test and verify
the results are exact vs. grossly broken
2023-10-17 21:35:37 +02:00
1223772f14 Scheduler: implement thread access logic
T thread holding the »Grooming Token" is permitted to
manipulate scheduler internals and thus also to define new
activities; this logic is implemented as an Atomic lock,
based on the current thread's ID.
2023-10-17 20:37:32 +02:00
862933e809 Scheduler: define API for Layer-2
Notably both Layers are conceived as functionality providers;
only at Scheduler top-Level will functionality be combined with
external dependencies to create the actual service.
2023-10-17 19:20:53 +02:00
0431a14584 Scheduler: Layer-1 complete and tested 2023-10-17 04:35:58 +02:00