On Wed, Mar 27, 2024 at 2:33 PM Tim Rowledge <tim@rowledge.org> wrote:


> On 2024-03-26, at 10:58 PM, Vanessa Freudenberg <vanessa@codefrau.net> wrote:
>
> we have no actual scheduler that gives a fair share of time to all runnable processes.


I have to admit that I can't even work out what we really mean by "a fair share of time"! Obviously, what we *really* mean in any particular case is that "a fair share" equals "my processes get everything they want and to hell with the rest"

LOL. Well Linux's CFS ("Completely Fair Scheduling") is around 10,000 lines of code ;)

But I'd say the minimum of fairness would be that all runnable processes should make progress all the time. How much time is given to each is debatable, except that higher priority processes should get relatively more time. And "all the time" means that every one of them should be serviced at least once every x milliseconds.
 
We do have a couple of relatively simple things almost ready to provide some improvement;
a) asynchronous file access, which has had a prim plugin for.. a couple of decades? AsynchFile is in the default image but has not users.

Using that is just a lot less convenient I guess, and we'd have to change a lot of code. But we could perhaps implement the current file prims in terms of the async prims, meaning that instead of waiting in the VM we'd wait in the image, so other processes could run in the meantime. That should improve performance dramatically for code that's i/o heavy but distributed across multiple processes (e.g., loading multiple bitmap files for game graphics, or servicing multiple http requests simultaneously).
 
b) sockety stuff, where it's almost defined that there will be an appreciable (in cpu terms) time waiting. I *think* the unix plugin does some stuff asynchronously, but not sure about higher level prim calls.
 
Socket code is pretty much async. Chris mentioned waitUntil... which uses semaphores the VM signals when the data is actually available/sent.

Even just making that sort of thing trigger a yield event would surely improve matters for server-type usage?

Not when the waiting happens in a primitive, as is the case with file access. We'd really need to use AsynchFile.

Vanessa