Poor performance / lockup with STM

前端 未结 3 1366
-上瘾入骨i
-上瘾入骨i 2021-02-02 12:24

I\'m writing a program where a large number of agents listen for events and react on them. Since Control.Concurrent.Chan.dupChan is deprecated I decided to use TCha

3条回答
  •  天命终不由人
    2021-02-02 12:54

    Adding to what Neil said, your code also has a space leak (noticeable with smaller n):Space leak After fixing the obvious tuple build-up issue by making tuples strict, I was left with the following profile:Profile with strict tuples What's happening here, I think, is that the main thread is writing data to the shared TChan faster than the worker threads can read it (TChan, like Chan, is unbounded). So the worker threads spend most of their time reexecuting their respective STM transactions, while the main thread is busy stuffing even more data into the channel; this explains why your program hangs.

提交回复
热议问题