Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to discover if a transaction is frequently aborting?

Tags:

haskell

ghc

stm

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?

like image 690
luisgabriel Avatar asked Nov 11 '15 23:11

luisgabriel


Video Answer


1 Answers

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.)

like image 53
Alexander Batischev Avatar answered Sep 18 '22 13:09

Alexander Batischev