GeeCON Prague 2014*
The moose likes Performance and the fly likes poor performance reading webservice and insert database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Performance
Bookmark "poor performance reading webservice and insert database" Watch "poor performance reading webservice and insert database" New topic
Author

poor performance reading webservice and insert database

Anderson Daniel Gomes
Greenhorn

Joined: Oct 25, 2012
Posts: 5

Hello,

I have one application swing that reading one table, query one webservice and after that insert in another table.
But today performance is very poor because I do this row by row.

How I could to improve performance to this scenery.

thanks
Daniel
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

How do you know that the poor performance is caused by inserting row-by-row?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Anderson Daniel Gomes
Greenhorn

Joined: Oct 25, 2012
Posts: 5
because I get more time to insert than to query the webservice.
I think if I do queue to query webservice to don´t wait the database the application will be better, but I don´t know how do that yet
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

So my point is that unless you have specific metrics showing exactly what it taking the most time, any attempts to optimize is pointless. Have you run a profiler that shows it is the inserts that are taking the most time, and not the web service call (for example)? Perhaps you have, in which case great!!

It's hard to give you specific advice without seeing you code - and please don't post hundreds of lines showing us. A short, self contained, correct example is what we prefer (see this).

If I am reading your second post correctly, you are asking how to make a bunch of webservice calls, queue the results, and then have a separate thread process them off and insert to the database?
Anderson Daniel Gomes
Greenhorn

Joined: Oct 25, 2012
Posts: 5
Sorry By bad english !

here the code the get data from database as pages:



code that read the webservice and insert on database:
parameter service is only parameter to webservice like as login and password
parameter p is the values that change to query webservice



Let me try to explain better my point, I think that the access the webservice and insert is not so bad, but if make I multithread could be better, don´t it ?
the problem is that I don´t know how do or if is realy better !

best regards !!
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11351
    
  16

Anderson Daniel Gomes wrote: I think that the access the web service and insert is not so bad, but if make I multithread could be better, don´t it ?
the problem is that I don´t know how do or if is realy better !

So that goes back to my first point. You don't have any empirical evidence for where the slowdown is - you're just guessing. The first rule of optimization is to not waste time optimizing anything until you know where the slowdown is.

Further...many people don't realize that multi-threading is not a panacea. There is a cost to making an application multi-threaded. You now need to have something controlling and managing those threads. While the manager is running, you can't do anything else. Granted, it isn't much time, but there is some. And let's not forget about the complexity it adds to your program, making it much harder to debug and maintain.

So...if your code is spending all its time waiting for the return of the web service call, making it multi-threaded won't help. Each thread still has to wait for a response, and if you hammer the server with requests, it may take it LONGER to return each one over doing it sequentially.

If your code has to wait one second for the web service calls to get their response, and your database insert is taking a millisecond...it's probably a waste of time trying to optimize your database inserts to take less time - you'll still be waiting for the web service to return.
Anderson Daniel Gomes
Greenhorn

Joined: Oct 25, 2012
Posts: 5
ok, I understand... so,thanks by your help !
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

I'd say that it might be possible to speed things up by doing them in batches. It would mean modifying the webservice and/or the DAO so that they would support processing more than one item/record per call, and it sounds like a lot of work.

Even if such change is achievable for you, you should try to estimate the potential savings by eg. measuring the time the webservice processing takes and comparing it with the network roundtrip time.
Anderson Daniel Gomes
Greenhorn

Joined: Oct 25, 2012
Posts: 5
Yes, I agree that could make insert as batch could give more performance, I´ll think how I can do this !!

I´ll measuring the time of the webservice and the database to have an idea better and know if is possible get more performance !

thanks !
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7892
    
  21

Anderson Daniel Gomes wrote:I´ll measuring the time of the webservice and the database to have an idea better and know if is possible get more performance !

But don't change anything unless you can prove that it's worth the effort.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: poor performance reading webservice and insert database