Re: Optimizing JDBC code

2011-08-10 Thread Shoeb Bhinderwala
Many thanks for adding this feature. Without it the Clojure code would have been left in the dust. On Aug 9, 11:46 pm, Sean Corfield wrote: > On Tue, Aug 9, 2011 at 9:39 AM, Shoeb Bhinderwala < > > shoeb.bhinderw...@gmail.com> wrote: > > With these options added the Clojure code runs just about a

Re: Optimizing JDBC code

2011-08-09 Thread Sean Corfield
On Tue, Aug 9, 2011 at 9:39 AM, Shoeb Bhinderwala < shoeb.bhinderw...@gmail.com> wrote: > With these options added the Clojure code runs just about as fast as > Java. I set the fetch size to 1000 for both of them. > > Average run times to load 69,000 records: > > Java = 2.67 seconds > Clojure =

Re: Optimizing JDBC code

2011-08-09 Thread Colin Yates
Nice work getting to the bottom of this. Sent from my iPad On 9 Aug 2011, at 17:39, Shoeb Bhinderwala wrote: > Hi Sean – > > With these options added the Clojure code runs just about as fast as > Java. I set the fetch size to 1000 for both of them. > > Average run times to load 69,000 records:

Re: Optimizing JDBC code

2011-08-09 Thread Shoeb Bhinderwala
Hi Sean – With these options added the Clojure code runs just about as fast as Java. I set the fetch size to 1000 for both of them. Average run times to load 69,000 records: Java = 2.67 seconds Clojure = 2.72 seconds Thanks Shoeb On Aug 9, 12:54 am, Sean Corfield wrote: > On Mon, Aug 8,

Re: Optimizing JDBC code

2011-08-08 Thread Shantanu Kumar
> So {:result-type :forward-only :fetch-size 1000} in the vector before your > SQL string should provide the same optimization as in the Java code. Please > let us know the results of your next test with those options added. As per this post http://blog.lishman.com/2008/03/jdbc-fetch-size.html act

Re: Optimizing JDBC code

2011-08-08 Thread Sean Corfield
On Mon, Aug 8, 2011 at 5:12 PM, Dmitry Gutov wrote: > Like the doc says, `with-query-results` takes additional options > before the query string. > Yup, this is a recent enhancement. You can either pass a PreparedStatement that you've built and configured instead of a SQL string or you can pass

Re: Optimizing JDBC code

2011-08-08 Thread Dmitry Gutov
Like the doc says, `with-query-results` takes additional options before the query string. In your case, it should be something like this: (sql/with-query-results recs `[{:fetch-size 1000} ~query-str ~@bvs] (doall recs)) -- You received this message because you are subscribed to the Google Gr

Re: Optimizing JDBC code

2011-08-08 Thread Shoeb Bhinderwala
Sean/Stuart/Others - My apologies to the group. I found out why my Clojure code runs slower than Java. The Java code uses the setFetchSize() method to retrieve data in batch: myResultSet.setFetchSize(1000); myResultSet.setFetchDirection(ResultSet.FETCH_FORWARD); Without

Re: Optimizing JDBC code

2011-08-08 Thread Shoeb Bhinderwala
You are right Michael. I misunderstood Colin's statement. As Stuart suggested I am profiling the code and will share the results with the group soon. On Aug 8, 4:33 am, Michael Wood wrote: > Hi Shoeb > > On 7 August 2011 01:51, Shoeb Bhinderwala wrote: > > > I am not guessing. I measured the pe

Re: Optimizing JDBC code

2011-08-08 Thread Michael Wood
Hi Shoeb On 7 August 2011 01:51, Shoeb Bhinderwala wrote: > I am not guessing. I measured the performance of the query using plain > Java and Clojure. That's not what he was saying. In your first message you said: >>> I am assuming that most of the extra time is spent converting the results >>

Re: Optimizing JDBC code

2011-08-08 Thread jaime
Thank you for your information! I think I will start with c.j.j's test code :) On Aug 7, 3:08 pm, Sean Corfield wrote: > On Sat, Aug 6, 2011 at 11:04 PM, jaime wrote: > > Hi guys, I just want to learn using databases in Clojure, can you > > suggest where to start? by looking at source code o

Re: Optimizing JDBC code

2011-08-07 Thread Stuart Sierra
Hi Shoeb, At this point, we probably need more data to give a meaningful answer. Different core data structures and different coding conventions can mean that "the same code" in Clojure and Java will behave quite differently. Try profiling your Clojure code with a Java profiler such as VisualVM

Re: Optimizing JDBC code

2011-08-07 Thread Sean Corfield
On Sat, Aug 6, 2011 at 11:04 PM, jaime wrote: > Hi guys, I just want to learn using databases in Clojure, can you > suggest where to start? by looking at source code of clojure.java.jdbc/ > clojure.contrib.sql or there's some tutorial/document that I can start > with? > The tests in c.j.j are pr

Re: Optimizing JDBC code

2011-08-07 Thread Sean Corfield
On Sat, Aug 6, 2011 at 10:51 PM, Shoeb Bhinderwala < shoeb.bhinderw...@gmail.com> wrote: > I switched to clojure.java.jdbc. Found no difference at all. It is > still about 10 times slower than java. > Thanx. I wanted to eliminate reflection as the potential culprit. Have you tried Clojure 1.3, j

Re: Optimizing JDBC code

2011-08-07 Thread Shantanu Kumar
On Aug 7, 10:51 am, Shoeb Bhinderwala wrote: > I switched to clojure.java.jdbc. Found no difference at all. It is > still about 10 times slower than java. I guess you can now get c.j.jdbc and put (time ...) wrappers in the call path in it to see where is the time mostly spent. Do share your fi

Re: Optimizing JDBC code

2011-08-06 Thread jaime
Hi guys, I just want to learn using databases in Clojure, can you suggest where to start? by looking at source code of clojure.java.jdbc/ clojure.contrib.sql or there's some tutorial/document that I can start with? Thanks, Jaime On Aug 7, 1:51 pm, Shoeb Bhinderwala wrote: > I switched to clojure

Re: Optimizing JDBC code

2011-08-06 Thread Shoeb Bhinderwala
I switched to clojure.java.jdbc. Found no difference at all. It is still about 10 times slower than java. On Aug 6, 8:54 pm, Sean Corfield wrote: > On Sat, Aug 6, 2011 at 4:51 PM, Shoeb Bhinderwala < > > shoeb.bhinderw...@gmail.com> wrote: > > In one test case, I loaded 69,099 records. The Java c

Re: Optimizing JDBC code

2011-08-06 Thread Sean Corfield
On Sat, Aug 6, 2011 at 4:51 PM, Shoeb Bhinderwala < shoeb.bhinderw...@gmail.com> wrote: > In one test case, I loaded 69,099 records. The Java code took 5 > seconds to execute the query and create as many objects. Clojure code > took 50.43 seconds. > Try using clojure.java.jdbc instead of clojure.

Re: Optimizing JDBC code

2011-08-06 Thread Shoeb Bhinderwala
I am not guessing. I measured the performance of the query using plain Java and Clojure. In one test case, I loaded 69,099 records. The Java code took 5 seconds to execute the query and create as many objects. Clojure code took 50.43 seconds. The JVM settings are the same - both are initialized t

Re: Optimizing JDBC code

2011-08-06 Thread Colin Yates
That assumption needs checking - first rule of performance analysis: check, don't guess :) For example, is the java code using an existing connection versus clojure creating one? I would also time the cost of creating 10 clojure maps of a similar structure. Finally - 100,000 is big enough to