sql - Python, SQlite 3 insert super slow -


for reason insert instruction painfully slow.

by painfully slow, mean go 400 updates second 5.

this method in question:

@app.route('/senddata/<path:data>', methods=['post']) def receivedata(data): #data = '0,2c7,2c6,1c8,2c2,1' always.     def h(point):         cur.execute("insert points (x, y) values({},{});".format(*point.split(",")))         g.db.commit()      cur = g.db.cursor()     #list(map(h, data.split("c"))) enables slow.     return "done" 

when uncomment map, goes painfully slow. tried other method, same thing.

def receivedata(data): #data = '0,2c7,2c6,1c8,2c2,1' always.     cur = g.db.cursor()     cur.execute("insert points (x, y) values({}, {});".format(*data.split("c",1)[0].split(",")))     g.db.commit()     if data.count("c") == 0:         return "done"     else:         return receivedata(data.split("c",1)[1]) 

i don't think need commit every single insert, putting @ end of each function makes no difference.

i suggest collect data want insert , build multi-row inserts (you test performance wise limit best) 100 or more points inserted @ 1 time.

unfortunately depending on version, there not typical insert ... values(...), values(..), ... know dbms, there solution in doing adapted question

insert 'points' (x, y)       select 0 'x', 2 'y' union select 7, 2 union select 6, 1 union select 8, 2 union select 2, 1 

Popular posts from this blog