core-async

2021-06-14T14:42:40.026400Z

Is there any way to get like a thread id inside a go block? I'd like to demo the fact that using a go block gives you access to a pool of threads

mpenet 2021-06-14T14:43:55.026700Z

(.getId (Thread/currentThread))

mpenet 2021-06-14T14:45:08.027900Z

this will show one of the threads used to "schedule" go blocks, I am not sure it demonstrates the "availability" of a real thread pool in that sense

mpenet 2021-06-14T14:45:25.028300Z

since you're not supposed to run (in the IO sense) anything on these

mpenet 2021-06-14T14:45:47.028500Z

but maybe you already know about all this

2021-06-14T14:48:20.029400Z

I don't think this is what I'm looking for but I'm a little new to core.async

ghadi 2021-06-14T14:52:23.030100Z

why don't you close-over a thread id when launching the go blocks?

2021-06-14T14:53:07.030500Z

Like wrapping the go block in a let?

2021-06-14T14:53:37.031600Z

Wouldn't all my go block threads then share the same 'thread id'?

2021-06-14T14:53:55.032100Z

I'm sure I'm wrong

2021-06-14T14:54:05.032400Z

Just wanted to ask the question 🙂

ghadi 2021-06-14T14:54:06.032500Z

(let [launch (fn [id] (async/go ....))]
  (mapv launch (range 50)))

ghadi 2021-06-14T14:54:29.032700Z

or some variation thereof

2021-06-14T14:55:39.034Z

I want to keep my presentation really simple because I'm pitching Clojure and Core.async to my team at work, so I don't want to do anything too clever. This would be hard to explain

dpsutton 2021-06-14T15:02:46.035400Z

can you explain with words what your ideal demo would demonstrate? ie, "using a go block gives you access to a pool of threads"

dpsutton 2021-06-14T15:04:06.036400Z

(err, not ie, but explain more that phrase. sorry 🙂

2021-06-14T15:05:34.037700Z

I'd like to demonstrate that when you queue your writes to the cloud graph database using a core async channel, and then consume and execute them in a go block, the writing happens faster because it's done by a pool of threads

2021-06-14T15:06:21.038500Z

I'd like to demonstrate that the pool of threads really does exist without any more code than a naked go block

mpenet 2021-06-14T15:06:56.039Z

go blocks will only schedule operations on channels (and return one), they will not spin threads for IO by magic (like in golang)

2021-06-14T15:07:14.039400Z

ohhhh

mpenet 2021-06-14T15:08:03.040300Z

stuff you do inside of them might use a threadpool, or async/thread or wait on other go blocks return value (a chan) etc, but there's no threadpool involved other that the one used by the go block implementation, which you shouldn't rely on

mpenet 2021-06-14T15:08:19.040600Z

(in short)

mpenet 2021-06-14T15:09:21.041800Z

that's a common misconception that go blocks are lightweight threads, it's not really the same

mpenet 2021-06-14T15:10:07.042100Z

it depends on your definition of that I guess

dpsutton 2021-06-14T15:10:41.042600Z

i treat core.async as almost exclusively a coordination library. it's for communication. but i think you could demonstrate how easy pipeline-blocking could be adapted here.

mpenet 2021-06-14T15:10:56.042900Z

yeah good point

mpenet 2021-06-14T15:11:20.043300Z

pipeline-* is a good thing to show off

2021-06-14T15:19:18.044200Z

how did I miss pipeline-blocking, I read the api docs 😆

ghadi 2021-06-14T15:19:20.044300Z

making a pitch for something is harder when you're less familiar with it

ghadi 2021-06-14T15:19:28.044600Z

can work against causes

2021-06-14T15:19:29.044700Z

you said it

dpsutton 2021-06-14T15:20:48.045600Z

i'd be prepared for the question "why not some concurrent queue and a fixed thread threadpool pulling from the queue?"

alexmiller 2021-06-14T15:33:25.047400Z

ie, an executor - and that is sufficient in a lot of cases. channels give you a bit better composability and features like transducers on the channel, alt (select) which is simply unavailable in Java, and things like the pipeline fns

2021-06-14T15:37:32.049900Z

I adore core.async for its intended use (coordination between concurrent processes) but I've found that with most PRs that introduce core.async: • don't actually solve the problem at hand • misunderstand the purpose of core.async and use it incorrectly in a way that will not show up in tests / dev envs • could have been much simpler as an executor and a queue or just a few calls to future

2021-06-14T15:38:27.051Z

I include my own first usages of core.async here, I totally ruined an app by adding core.async code that failed in a way that didn't show up until the system was under load

2021-06-14T15:39:44.051800Z

if I was paranoid I'd suggest that core.async was a conspiracy by core.async consultants to get contracts 😆

alexmiller 2021-06-14T15:41:07.052Z

I can assure you that's not the case :)

2021-06-14T15:42:41.053800Z

I know you are developing the lib in good faith. It's like the light saber hanging on the display stand - it attracts attention because it's so cool, but most of the time that eagerness to use it just ends in tragedy

2021-06-14T15:42:55.054200Z

but when used for what it's meant for, it's the greatest

2021-06-14T15:43:39.055Z

I think I'll delete the part of my demo about writing to the DB and simply show my team what I do have, which is Java interop. If I don't know this tool well enough, then it's not the right time to pitch it at work

dpsutton 2021-06-14T15:45:19.055600Z

advocate for benefits you have already felt and go with it

2021-06-14T15:45:32.055800Z

Yeah I like that

2021-06-14T19:46:02.055900Z

Does such a thing exist?

2021-06-14T19:54:42.056100Z

I worded it for humor / hyperbole, but specifically Timothy Baldridge has a talk where he shares the kinds of fix he ends up making in core.async code while contracting.