views:

42

answers:

2

I'm working on a software that does extensive queries to a database which is has a http interface. So my program parses and handles queries that are in form of long http:// addresses..

I have realized that the bottleneck of this whole system is the querying and the data transfer barely goes above 20KB/s even though I am sitting in the university network with a gigabit connection. Recently a friend of mine mentioned that I might have written my code in an ineffective way and that might be reason for the lack of speed in the process. So my question is what is the fastest/most effective way of getting data from a web source in Java.

Here's the code I have right now:

private void handleQuery(String urlQuery,int qNumber, BufferedWriter out){
    BufferedReader reader;
    try{
        // IO - routines: read from the webservice and print to a log file
        reader = new BufferedReader(new InputStreamReader(openURL(urlQuery)));
        ....
        }
     }

private InputStream openURL(String urlName)
    throws IOException
 {
    URL url = new URL(urlName);
    URLConnection urlConnection = url.openConnection();
    return urlConnection.getInputStream();
 }
A: 

There is nothing in the code that you have provided that should be a bottleneck. The problem is probably somewhere else; e.g. what you are doing with the characters after you read them, how the remote server is writing them, network or webproxy issues, etc.

Stephen C
well what happens with the characters is:- parsing- processing and storing the data in a bunch of objectsI know that the code is not memory effective (aka it's quite likely that there are double copies of some certain information) but I am not sure why the querying is so ridicilously slow
posdef
As @ZZ Coder suggests, try profiling the client and look any other evidence you can find using system and network monitoring. You need to have pretty conclusive evidence that the problem is on the server side before you start pointing the finger at it ... especially if it is someone else's responsibility.
Stephen C
any tips for a good profiler? I had used "Shark" for one of my courses which was a fantastic tool to analyze the code, but it works only for macs and for c/c++ code as far as i know...
posdef
+1  A: 

Your code looks good to me. The code snippet doesn't explain the slow read.

Possible problems are,

  1. Network issues. Do an end-end network test to make sure network is as fast as you think.
  2. Server issues. Maybe the server is too slow.
  3. Thread contention. Check if you have any thread issues.

A profiler and network trace will pin-point the problem.

ZZ Coder
Well I think the network (at least from my end) is pretty stable, I mean when I do anything else using the network (for example downloading articles, images, even big files like linux distros) I get several MB/s speed. I am not using threading (yes, it's a disaster I know but I couldn't manage to handle the data in a thread safe, effective way. after all it's my first big project) I am inclined more and more towards blaming the remote server for the speed, but just wanted to make sure there isn't I can do to speed things up..
posdef