How to discover if a transaction is frequently aborting?
Asked Answered
C

1

14

I'm trying to debug a program that uses STM. The ThreadScope readings is pointing out a very high CPU activity as you can see here:

enter image description here

So I'm trying to find out if this is happening due to a transaction that frequently aborts. The first thing that I thought was using something like this to test:

atomically $ do
  someWork 
  ...
`orElse` do
  unsafeIOToSTM $ traceEventIO "transaction aborted!"
  retry

But I'm not sure if this is correct or if this is the best approach to debugging in an STM scenario. Any ideas?

Confluent answered 11/11, 2015 at 23:40 Comment(3)
That would have been my approach as well.Crosslink
What results did you get from this approach?Phylys
There are no traces. If this approach is correct, no transaction is aborting.Confluent
A
3

Use stm-stats package. It provides trackSTM that you should use instead of atomically, and dumpSTMStats :: IO () that will provide something like this:

STM transaction statistics (2011-10-09 12:28:37.188951 UTC):
Transaction     Commits    Retries      Ratio
_anonymous_           1          0       0.00
reader                1         23      23.00
writer               23          0       0.00

(Transaction names will be generated automatically, but there's helpers to set your own.)

Animated answered 25/4, 2016 at 13:37 Comment(3)
Sorry for the long delay to respond. It seems that this package is not updated for a long time. I'll take a look how they check for retries. Thanks!Confluent
I wouldn't be concerned about lack of updates: 1) Joachim, the maintainer, is well-known in the community; 2) the package is in Stackage LTS, which means it at least builds.Animated
Just had some time to test stm-stats and it worked perfectly! The problem was indeed a transaction frequently aborting. Thank you!Confluent

© 2022 - 2024 — McMap. All rights reserved.