clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
mpenet 2021-01-25T11:51:08.001700Z

@alexmiller I was wondering, why is pipeline not creating/blocking a thread later in the process, right before running a task. Right now it will create/block-on n threads even if nothing happens. I think that basically creates higher memory usage for nothing.

mpenet 2021-01-25T11:51:28.002100Z

it could be like this instead no? https://github.com/mpenet/core.async/commit/e9bb61d (edited to latest version)

mpenet 2021-01-25T11:52:02.002800Z

that one would cost more in context switches potentially, but at least, when the input chan is empty, 0 thread usage and low memory

mpenet 2021-01-25T11:59:15.004100Z

I guess that patch could create some more work if the chan always contains values (async/thread call, since it's from a cached thread pool), but it's probably negligible given the usage context

alexmiller 2021-01-25T14:31:23.004900Z

I think with your change, it's no longer bounded by n at all

mpenet 2021-01-25T14:50:39.005700Z

There would never be more than n process calls parallel.

mpenet 2021-01-25T14:50:57.006100Z

Since we take the result before recur

mpenet 2021-01-25T14:52:51.006700Z

Actually no, you re right I think

mpenet 2021-01-25T15:03:51.009600Z

Need less kids around to be able to play in repl, you put some doubt. But I think since every loop parks on process, every loop never runs more than one task at a time. At least it was the idea

mpenet 2021-01-25T15:20:15.010100Z

not to mention I based that on a 6yo version of master....

mpenet 2021-01-25T15:25:49.010300Z

more up to date https://github.com/mpenet/core.async/commit/e9bb61d

mpenet 2021-01-25T15:26:25.010900Z

a quick unscientific sprinkling of prn statements over an atom seems to show it's indeed limited to n

mpenet 2021-01-25T15:37:09.011200Z

tested with that horror in the same ns: https://gist.github.com/mpenet/1c3d9e052543ab1285ddb5ea9fc8285a

mpenet 2021-01-25T15:37:11.011300Z

mpenet 2021-01-25T19:08:08.013300Z

@alexmiller should I create a Jira with proper patch & test?

alexmiller 2021-01-25T19:17:16.013700Z

what problem are we trying to solve here?

alexmiller 2021-01-25T19:17:57.013900Z

using fewer threads?

mpenet 2021-01-25T19:22:53.015400Z

Yes, if you don't have n+ items to consume it will use less threads, potentially 0 if you are waiting on values to be sent to the chan, or when you are dealing with bursty loads.

alexmiller 2021-01-25T19:24:23.017300Z

at the cost of spinning up those threads when needed

mpenet 2021-01-25T19:24:42.017900Z

It doesn't change behavior if your chan producers are ahead of the pipeline "runner"

mpenet 2021-01-25T19:24:47.018100Z

Yes

mpenet 2021-01-25T19:25:06.018900Z

But you never have more than n threads running tasks at a time

alexmiller 2021-01-25T19:25:16.019100Z

you can file something. to really evaluate I would need to dig out the original design stuff for this

alexmiller 2021-01-25T19:25:31.019300Z

I don't think that's going to happen soon

mpenet 2021-01-25T19:26:57.021700Z

It's possible to emulate this pattern with pipeline-async + thread on the current version. It's a bit ugly but it saves resources when idling

mpenet 2021-01-25T19:27:12.022100Z

Alright, will do

mpenet 2021-01-25T19:27:15.022300Z

Thanks

alexmiller 2021-01-25T19:29:39.024300Z

well, I'd lead with the problem

mpenet 2021-01-25T19:29:49.024700Z

Lastly, since iirc we have a cached thread pool behind thread the price to "acquire" new threads is low, there's a lot of reuse going on

alexmiller 2021-01-25T19:30:21.025100Z

cached thread pool threads die, so hard to say

mpenet 2021-01-25T19:32:17.025700Z

They remain for 60s, it's quite a lot

mpenet 2021-01-25T19:33:15.026400Z

That is what i remember, i could be wrong

alexmiller 2021-01-25T19:39:33.026600Z

that's right