Commit graph

4591 commits

Author SHA1 Message Date
86b90fbf84 Scheduler: draft high-level API for building a Job schedule
The invocation structure is effectively determined by the
Activity-chain builder from the Activity-Language; but, taking
into account the complexity of the Scheduler code developed thus far,
it seems prudent to encapsulate the topic of "Activities" altogether
and expose only a convenience builder-API towards the Job-Planning
2023-11-06 06:00:00 +01:00
c377ac7d46 Scheduler: observe start and deadline explicitly given by POST
With the previous change, we allways have an execution scope now,
which (among other things) defines a time-window (start,deadline).
However, the entrance point to an Activity-chain, the POST-Activity
also defines a time window, which is now combined with this scope
by maximum / minimum constraining.
2023-11-06 04:18:00 +01:00
72258c06bd Scheduler: reconciled into clearer design
The problem with passing the deadline was just a blatant symptom
that something with the overall design was not quite right, leading
to mix-up of interfaces and implementation functions, and more and more
detail parameters spreading throughout the call chains.

The turning point was to realise the two conceptual levels
crossing and interconnected within the »Scheduler-Service«

- the Activity-Language describes the patterns of processing
- the Scheduler components handle time-bound events

So by turning the (previously private) queue entry into an
ActivationEvent, the design could be balanced.
This record becomes the common agens within the Scheduler,
and builds upon / layers on top of the common agens of the
Language, which is the Activity record.
2023-11-04 04:49:13 +01:00
62a1310566 Scheduler: rearrange internal API to expose context data
This is the first step to address the conceptual problems identified yesterday,
and works largely as a drop-in replacement. Instead of just retrieving
the Activity*, now the Queue entry itself is exposed to the rest of the
scheduler implementation, augmented with implicit conversion, allowing
all of the tests to remain unaltered (and legible, without boilerplate)
2023-11-04 01:59:42 +01:00
747e522c7e Scheduler: design-problems while integrating deadline
the attempt to integrate additional deadline and significance parameters
unveils a design problem due to the layering of contexts

- the Activity-Language attempts to abstract away the ''Scheduler mechanics''
- but this implementation logic now needs to pass additional parameters
- and notably there is the possibility of direct re-scheduling from within
  the Activity-Dispatch

The symptom of this problem is that it's no longer possible
to implement the ExecutionCtx.post() function in the real Scheduler-context
2023-11-03 03:33:23 +01:00
b49de0738d Scheduler: implement automatic clean-up of outdated entries
Hooked into the existing processing logic at Layer-2,
and relying on the information functions of Layer-1
2023-11-03 01:17:10 +01:00
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
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