• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delay in Method Return  RSS feed

 
Prabhash Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
        I am working on JAX-RS application and i am working on performance tuning of my application.I am reading system time before processing starts and before method returns.It is giving good time before returning of method.But when i am reading system at before and after calling position it is taking much time which means before returning it is ok but after method returns at calling place at that place it is taking much time.Below are both method cose as well as calling place code.

Method Code:



Code where above method is called:



OutPut:

After Execution:1.069
Service===4.0

See before method return it is 1.06 sec but at the place wher this method returns it is 4 sec.Can anyone provide me solution.What i need to do to minimize it.

Thanks,
Prabhash
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Between getting the initial timestamp in getAllOrders (the l1 variable) and getting the initial timestamp in the getAllOrders method (the s1 variable), the code potentially loads some classes and has to connect to the database (the getConnection call), and then create a prepared statement.  All of this takes time.  Most of the time difference will be the database side of things, so move the s1 bit to at least before the call to getConnection.

By the way, the oracle jdbc driver is a class 4 driver and so does not need you to load the class using Class.forName().
 
Prabhash Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
     I moved the time reading code before getConnection and i am getting following output.


After Execution:4.028
Service===4

Can i say this delay is due to database side not due to java code as i am a developer and database query is written by some database guy.

Thanks,
Prabhash 
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, the delay is at least in part down to this:


That is logging onto the database every time.
Depending on where this is going to run you might want to rethink that part.
For example, if this is a web app you would want a connection pool.

It's not the execution of the query as that doesn't happen until after your original place for setting s1.

In addition, the nature of Java means your timings are unreliable if you are doing this timing test in isolation.  As I said, it's possible you are also timing the loading of various classes, which would not be the case in normal execution.
 
Prabhash Mishra
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
    I am using DriverManager.getConnection() at my local host.This application is under testing on QA and performance.On QA and Performance i m using JNDI with connection pooling.Since i can't connect my localhost  with QA database using JNDI on Performance or QA server that's why i am using DriverManager to connect with QA database on my local.This is for testing purpose on my local.

On line 25 which is commented i am using to call JNDI.When i am sending WAR file to QA instance i use to comment the DriverManager Code and uncomment the JNDI code.on my local i don't have QADB or Performabce DB but i have to test application connecting to QADB or Prod DB.Since on production i am using JNDI with connection pooling with MAX=1000,MIN=100 and available connection on startup =200.So this will be ok with the performance issue or not please let me know.In the Query select* from i am using View instead of Table name.Can you tell me there will not be any performance issue or i have to do more optimization.

Thanks,
Prabhash
 
Dave Tolls
Ranch Hand
Posts: 2835
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't tell if you have to do more optimisation.
Only you can say that, based on whether it works fast enough for the requirements.

In addition, you are attempting to check performance in an environment that's very different to the real environment.
That you are not using a connection pool in your local env is the main example of that.
 
Tim Moores
Saloon Keeper
Posts: 3831
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
+1 for the points about loading the DB driver, and not using a connection pool.

What are you setting autocommit to false for a SELECT query?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!