From c6ae06e1d32b354715f908d723164149e4a02cdb Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 19 Sep 2019 12:43:08 -0700 Subject: [PATCH 1/2] Try wrapping an explicit transaction around the update query. --- bench/update_item_sql.exs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/bench/update_item_sql.exs b/bench/update_item_sql.exs index 2b8b68e..6236b01 100644 --- a/bench/update_item_sql.exs +++ b/bench/update_item_sql.exs @@ -30,16 +30,19 @@ ParallelBench.run( random_item_id = Enum.random(item_ids) random = :rand.uniform(100_000_000_000_000) - {:ok, %{num_rows: 1}} = - SQL.query( - Repo, - """ - UPDATE items - SET mumble3 = $1 - WHERE id = $2; - """, - ["New Mumble #{random}", random_item_id] - ) + {:ok, _} = + Repo.transaction(fn -> + {:ok, %{num_rows: 1}} = + SQL.query( + Repo, + """ + UPDATE items + SET mumble3 = $1 + WHERE id = $2; + """, + ["New Mumble #{random}", random_item_id] + ) + end) end, parallel: 10, duration: 10 From a338b3d8d0f569bef1b956b276b28208fe1f01ae Mon Sep 17 00:00:00 2001 From: Eric Scouten Date: Thu, 19 Sep 2019 12:53:44 -0700 Subject: [PATCH 2/2] Try suggestion of using transaction isolation level. --- bench/update_item_sql.exs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bench/update_item_sql.exs b/bench/update_item_sql.exs index 6236b01..97ddcf5 100644 --- a/bench/update_item_sql.exs +++ b/bench/update_item_sql.exs @@ -32,6 +32,8 @@ ParallelBench.run( {:ok, _} = Repo.transaction(fn -> + SQL.query!(Repo, "SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;") + {:ok, %{num_rows: 1}} = SQL.query( Repo,