24 ms·
Scheduling threads like Thomas Jefferson
- bdcravens 2y agoJefferson said we should rewrite the constitution every 19 years, so I assumed that means if threads haven't completed in some amount of time, to just blow them all away and start over lol
- deleted 2y ago[deleted]
- js8 2y agoI am not sure why would you want to do this. If I take an example of the bottling pipeline, it seems to me that the best way to process the bottles on an SMP system is to have multiple threads where each thread is doing all the work for a single bottle, sequentially. Maybe, if the processes at each stage are I/O-bound, then it might make sense. But if they are CPU-bound, then I am not sure this way of pipelining helps - you're moving data between different CPUs, destroying cache locality.
- adrianmonk 2y agoI was about to suggest the same thing, and I still think it makes a lot of sense. However, the cache locality thing is complicated. Each bottle has data associated with it, but each processing stage might also have data. For example, maybe a particular stage uses a lookup table. Or maybe stages keep statistics as they process bottles. If you have one CPU doing all the work for a particular stage, then per-stage data stays in its cache. But if you have one CPU doing all the work for a particular bottle, then all the per-bottle data stays in its cache. So there's a trade-off that depends on the specifics.
- kitd 2y agoMore importantly, each processing stage may have external resources it needs to manage to do its function. In many cases, it makes more sense to let the stage own the resource for all bottles, than to have a per-bottle process having to contend for the resource at the point it's needed.
- hinkley 2y agoYou get very different Little’s Law shapes from the too for sure. Who here hasn’t bought themselves some time from vertically or horizontally scaling a database by hoisting a bunch of calculations up and out of the transaction? Do them before or after the constraint. The farther you have to reach to coordinate use of the constraint the better it might be to hand the inputs to the constraint and let an experts handle things.
- anonymoushn 2y agoYou probably gain some ILP or avoid some pipeline stalls by handling a lot of bottles at a time rather than one.
- hinkley 2y agoParticularly if you’re doing collision detection against static sets of data. Filter this data for entries that look this way. Or don’t look that way.
- shermantanktop 2y agoI’ve done something like this in large service ecosystems. It has two very unfortunate properties: - if the actual performance deviates from the predicted (scored) performance, the system easily enters a degenerate bottlenecked state. - and if that happens, the many internal queues make diagnosis, root causing, and confidence in a fix all exponentially worse. Now you might assert that this will be applied in situations where scores are accurate and brown failures do not occur. Those aren’t the situations I deal with.
- Joker_vD 2y agoThe algorithm in TFA, as I understand it, requires the scheduler to constantly monitor the queue lengths and reschedule the workers appropriately, as opposed to manually estimating the required number of workers for each stage and then never changing it.
- shermantanktop 2y agoThis is what happens with PID controllers. It is by definition a trailing view, and a single catastrophically bad request can cause catastrophic deviation of the whole system before the queue monitoring can "catch up."
- hinkley 2y agoIt’s possible to write a scheduler that looks like work stealing and can route unordered tasks around a poison pill. But we’ve generally found it works better for the worker to pull when its queue is empty, and of course if you have partially ordered events nobody can process (start or reject) those ordered tasks until the borked one finishes or times out. So the situation you describe can absolutely happen, but is not a given. It’ll depend on other decisions.
- jerf 2y agoThis also contains a hidden assumption that reallocation from one task to another is very, very expensive, so it's necessary to name the distribution of resources well in advance. This is clearly true for a physical production line. But if you are in the very common circumstance in the computer world where the switching time is significantly less than the amount of progress than can be made on a given task in some time, then the optimum scenario is just to do work as it becomes available, and in many cases, almost any scheduling algorithm that isn't deliberately constructed for maximum pathology will ensure that significant progress is made. That's why in the vast majority of circumstances you'll be running many things on many CPUs, you just throw all the work at the CPUs and let the chips fall where they may. Deliberate scheduling is a tool, but an unusual one, especially as many times the correct solution to tight scheduling situations is to throw more resources at it anyhow. (Trying to eke out wins by changing your scheduling implies that you're also in a situation where slight increases in workloads will back the entire system up no matter what you do.)
- hinkley 2y agoEven with lambdas you want a bit of server affinity because setup is nontrivial. If the job absolutely needs to get done we can get it done. But the opportunity cost is high and we can’t build a business around it. You want to prefer the warm path over the cold one.
- jerf 2y ago"if you are in the very common circumstance in the computer world where the switching time is significantly less than the amount of progress than can be made on a given task in some time, then the optimum scenario is just to do work as it becomes available" ... and if you aren't, then clearly, by the way "if-then" statements work, the "then" clause doesn't apply.
- limit499karma 2y agoI do not believe 'pipelining' and parallelism are interchangeable models and conflating them is a mistake. For example, consider a parallel processing system that in fact works strictly using a 'pipeline' of length 0, that is there is a hand-of from input to processing stage and processing of that input. And you can have n such parallel processing stages and voila 'parallelism'. Pipelines are strictly processing stages where the 'production of the input' and processing on the inputs are not synchronized. For example, one sends n requests to via a pipeline protocol to a remote server without waiting for acks for each input from the server. There may only be one such processing pipeline (and thus no parallelism) while there is pipelining.
- bee_rider 2y agoI don’t 100% follow your comment, so sorry if this is not quite right. But, I would consider pipelining to be a form or parallelism. It breaks up a task so that parts of it can be run simultaneously (in different stages of the pipeline, simultaneously). There are other ways to do parallelism of course, but it is a way. In your example, if there are multiple pipeline stages in this server, then the tasks should be worked on simultaneously, and so parallelism is occurring. Multi-core, SIMD, and pipelining. Parallelism has multiple dimensions.
- spc476 2y agoNot quite. Going back to the bottling example, a bottle has to be filled, capped, then labeled. At time 1, 1 bottle is filling up, pipeline is advanced. At time 2, bottle 2 is filling up, bottle 1 is being capped, pipeline is advanced. At time 3, bottle 3 is filling up, bottle 2 is being capped, and bottle 1 is being labeled. At time 4, bottle 1 is done. Each bottle has to go through the pipeline in sequence, and it takes three units of time for a bottle to go through the pipeline. Yes, once the pipeline is filled up, you have the three operations going on at the same time, but it's still a sequence of steps that need to be performed in order for any given bottle. To make it faster, you either have to decrease the time for a step (but you will always be capped with the slowest step), or go for parallelism---a separate pipeline (or pipelines). For example, with one pipeline, each step taking 1 unit of time, once the pipeline is filled, will take six units of time to make a six-pack (the first will take longer due to the latency in filling the pipeline). You can make five other pipelines, and then get a six-pack per unit of time (again, after filling all the pipelines). A single pipeline just makes the output have a predictable latency and time; multiple pipelines give you parallelism.
- pwdisswordfishz 2y ago"Those who sacrifice freedom for memory safety deserve neither" or something?
- mindcrime 2y agoAs I came up with this idea of scheduling described above, I bounced it off my friend Daniel Gustafsson who immediately replied “this reminds me a bit of Jefferson’s method” (of allocating seats in parliaments). Sounds like the author of this would be interested in Queueing Theory[1] (in the sense of being interested in mathematical formalisms to explore this stuff). Apportionment[2] is also studied as a very specific thing unto itself. There's a huge mass of published research "out there" dealing with queueing and scheduling. Not all of it pertains to "thread scheduling" but there's quite a bit of conceptual overlap between something like thread scheduling and job floor scheduling. And some of the stuff on apportionment likewise probably relates at least by analogy. [1]: https://en.wikipedia.org/wiki/Queueing_theory https://en.wikipedia.org/wiki/Queueing_theory [2]: https://en.wikipedia.org/wiki/Mathematics_of_apportionment https://en.wikipedia.org/wiki/Mathematics_of_apportionment