This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-20
Channels
- # announcements (10)
- # architecture (7)
- # babashka (49)
- # beginners (125)
- # calva (2)
- # chlorine-clover (33)
- # clj-kondo (15)
- # cljs-dev (18)
- # cljsrn (28)
- # clojure (91)
- # clojure-argentina (37)
- # clojure-austin (4)
- # clojure-dusseldorf (1)
- # clojure-europe (3)
- # clojure-france (2)
- # clojure-germany (2)
- # clojure-nl (4)
- # clojure-portugal (4)
- # clojure-spec (26)
- # clojure-uk (19)
- # clojuredesign-podcast (5)
- # clojurescript (19)
- # conjure (20)
- # core-async (4)
- # cursive (60)
- # data-science (4)
- # datomic (1)
- # duct (9)
- # emacs (11)
- # events (1)
- # fulcro (9)
- # graalvm (17)
- # jobs-discuss (7)
- # luminus (19)
- # malli (36)
- # meander (2)
- # off-topic (23)
- # pathom (2)
- # quil (1)
- # rdf (4)
- # re-frame (16)
- # reitit (10)
- # ring (21)
- # ring-swagger (1)
- # shadow-cljs (137)
- # spacemacs (10)
- # sql (27)
i’ve been hitting my head against a wall trying to figure some odd db behavior, perhaps someone could give me a hand:
i have two identical insert
statements with 5000 rows. executed individually they are pretty quick (ms). executed under a dorun pmap
, one of them will timeout at the default of 50 s, and the other will take 4 minutes or more. what’s going on here?
here’s a description of the table:
+-------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| x | binary(32) | NO | UNI | NULL | |
| y | mediumblob | YES | | NULL | |
+-------+------------+------+-----+---------+----------------+
i’m inserting x-y pairsWell, pmap
is almost never the right solution for concurrency... but... are you trying to use a single connection across both inserts? Are you trying to do them inside a transaction?
it’s not so much that i need pmap as i’m trying to replicate a db-layer bug that i have elsewhere, and this setup is exhibiting the same behaviour
And what type of db spec / datasource are you passing in the execute?
Also, which JDBC library are you using? clojure.java.jdbc
or next.jdbc
? And which database is this?
{
:host "localhost"
:dbtype "mysql"
:password "test"
:rewriteBatchedStatements true
:user "user"
:allowPublicKeyRetrieval true
:useSSL false
:useUnicode true
:characterEncoding "UTF-8" }
(jdbc/execute! conn (concat ["INSERT IGNORE INTO table (x,y) VALUES (?,?)"] rows) {:transaction? false :multi? true})
OK. So each execute
call will stand up a new connection to the DB. You'll definitely get contention in mysql from attempting two large locking inserts at the same time.
Oh, so you're avoiding a transaction around each SQL op and you are trying a single batch operation with 5,000 sets of parameters in the batch...
rewriteBatchedStatements
isn't going to help you here FYI
MySQL doesn't handle concurrent large inserts on a single table very well in my experience. You tend to get deadlocks.
Are you wrapping the (two) calls with your own transaction? If not, why are you trying avoid c.j.j setting up a transaction?
i believe it was changed to try and avoid deadlock issues, but it seems it hasn’t achieved that