Hi everyone -
I'm running weblogic6.1 sp1. We're creating an InitialContext, looking up a DataSource, and then getting a connection from the data source - pretty standard stuff.
Now, I was always under the impression that creating an initial context and doing a JNDI lookup were pretty expensive operations. However, in doing some timings, it looks like weblogic takes less than .10s to instantiate and InitialContext and return a DataSource, and more than 1s to return a connection.
Doesn't this seem a little strange?
Note: When I instantiate an InitialContext - I'm just calling "new InitialContext()".
-Scott
-
InitialContext and DataSource creating (3 messages)
- Posted by: Scott Gilpin
- Posted on: March 14 2002 15:04 EST
Threaded Messages (3)
- InitialContext and DataSource creating by Kashmiri Kaser on March 15 2002 12:03 EST
- InitialContext and DataSource creating by Kapil Israni on March 16 2002 12:30 EST
- InitialContext and DataSource creating by Eric Ma on March 21 2002 16:27 EST
-
InitialContext and DataSource creating[ Go to top ]
- Posted by: Kashmiri Kaser
- Posted on: March 15 2002 12:03 EST
- in response to Scott Gilpin
Hi Scott,
According to my experience with WebLogic, the "new InitialContext()" operation should not take longer than 60 to 100 milliseconds - and about the same for looking up the DataSource.
Usually the DataSource object takes about .7 second (650 to 750 milliseconds to be exact) to return connection for the first time (this includes new InitialContext(), lookup() and ds.getConnection()). That's a awfully large amount of time. After experiencing the above, I did the following trick (might not be a good programming practice, because you can easily be a victim of lost connection if you do not close() and refresh it properly):
- I created a DataSource instance as the private static member of the entity bean and a method to return a connection on this DataSource. Only the first time the DataSource is looked up (new InitialContext() and lookup()) and then it is assigned to the private static member of the bean. The next time (if ds != null) the method directly accesses the DataSource already lookedup as for example: (UserBean.staticDataSource).getConnection().
This reduced the total timing between the clients connect() call and returning the connection to about 250 to 300 milliseconds.
Thanks.
- KK -
InitialContext and DataSource creating[ Go to top ]
- Posted by: Kapil Israni
- Posted on: March 16 2002 12:30 EST
- in response to Kashmiri Kaser
Is is advisable to cache the "new IniialConext()" object and then using this one cached object for looking up Home Objects and DataSource Objects across the entire application.
-
InitialContext and DataSource creating[ Go to top ]
- Posted by: Eric Ma
- Posted on: March 21 2002 16:27 EST
- in response to Kashmiri Kaser
Which part of using DataSource takes up to 0.7 seconds? My understanding of your finding is:
1. Context ctx = new InitContext();
2. DataSource ds = (DataSource) ctx.lookup("MyDataSource");
3. Connection conn = ds.getConnection();
(omitted the try/catch stuff for clarity)
Step 1 takes 60 - 100 millisec
Step 2 also takes 60 - 100 millisec
Step 3 takes 700 millisec?
Or Steps 1+2+3 take 700 millisec?
Regardless, the ds.getConnection() step seems to be the most time-consuming part. I am curious how can you reduce the total time to 250 to 300 millisec by using a static reference to the DataSource object?
Anyway, thanks very much for the infomation.