On Sun, Apr 1, 2012 at 6:02 PM, Jeremy Evans <[email protected]> wrote: > On Sunday, April 1, 2012 1:19:08 AM UTC-7, Christian MICHON wrote: >> >> yes, I was doing something wrong. I need to do this instead: >> >> conn = DB.synchronize {|co| co} > > Note that while that may work in your case, it's not recommended, as it > returns the connection to the pool while you are still using it. You should > be doing: > > DB.synchronize do |conn| > stmt = conn.createStatement > ... > end
True. I'm setting conn at the beginning of my script, then I build specific few prepared statements, later on accessed through a hash. conn is never used again. > > Basically, you need to restrict your use of the conn object to the inside of > the block, so that the connection isn't returned to the pool until after you > are done using it. In a single threaded program, this doesn't matter, but > it is important in a multithreaded program. single thread, as this is performing massive imports into it. > > Anyway, I'm glad that it is working for you. For other readers, when you > need the maximum possible speed, using Database#synchronize and dealing with > the connection object is generally fastest, short of writing a native > extension in C/Java. Later on, this H2 db is connected to a sinatra web app. As I may include few prepared statements as well for some repetitive json generations, I'll keep in mind your advice. Earlier this afternoon I tried on my full scale production code. This gave me around 3x speed improvements, for less than 10 lines of code while keeping most of sequel logic. Quite a finding! Thanks again. -- Christian -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
