Solved

Http connection timeout

Posted on 2009-07-06
13
685 Views
Last Modified: 2012-05-07
Hi Experts,
In my web application i have an user uploading a file ~10MB and i need to parse the file they uploaded and move records into database before i can respond to client. My fear is that this process can take minutes(5-10mins) and might lead in connection timeout.
Is this a valid fear? If so any ideas as to what i can do to avoid it.

thanks
S
0
Comment
Question by:sunilramu
  • 5
  • 3
  • 2
  • +2
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 24785177
Connection timeout is not likely unless the upload gets broken in some way
0
 

Author Comment

by:sunilramu
ID: 24785196
Hi CEHJ,

Thanks! Can you please give or direct me to more details. As to why its not likely.

S
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 24785383
A connection timeout is unlikely since that only happens when there's no activity
0
 

Author Comment

by:sunilramu
ID: 24785436
CHEJ,
Do you mean no activity on the app server or web server. How does web server know that app server is still processing request. do they have open dialog when the processing is going on. i thought it was a disconnected interaction. Can you please point me to some literature as the what such a threshold(if exists) may be.

thanks again
S
0
 
LVL 7

Assisted Solution

by:nikhilmenon
nikhilmenon earned 50 total points
ID: 24787811
Well I can understand your fear and In my opinion there is a valid threat of a connection timeout. This is because:

a) You can't do anything with the file while it is being uploaded
b) Once it is uploaded and you are actually performing your operations on the file (the parsing, etc.) there is no response being sent by your server to the client which could mean "inactivity" to the client.

I think you can work around this by sending periodic progress updates about the percentage of work completed.
0
 
LVL 8

Expert Comment

by:WhiteMage
ID: 24789038
What java code are you using on the server side for uploading?

I know on downloading you can Resume the Download if the connection times out if the server supports that (i.e., "range:bytes=" in http header) along with setting the number of milliseconds for the time out.  The pseudo-code below is an example.
URL url = new URL("http://.../file.ext");

HttpURLConnection con = (HttpURLConnection)url.openConnection();
 

con.connect();

if(destFile.exists() && destFile.length() >= con.getContentLength()) {

  return(true); //download complete

}

con.disconnect();
 

boolean appendToFile = false;

int bytesDownloadedSoFar = 0;
 

if(destFile.exists()) {

  bytesDownloadedSoFar = destFile.length();

  appendToFile = true;
 

  con.addRequestProperty("Range","bytes=" + bytesDownloadedSoFar + "-");

  //just in case

  con.setRequestProperty("Range","bytes=" + bytesDownloadedSoFar + "-");

}
 

con.setConnectTimeout(30000);

con.setReadTimeout(30000);

con.connect();
 

//Start downloading...

...

Open in new window

0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 92

Accepted Solution

by:
objects earned 400 total points
ID: 24790164
connection timeout will not cause a problem as it has nothing to do with your upload activity. Connection timeout will only only occur if there is a delay getting a connection. It has nothing to do with the subsequent upload.
0
 

Author Comment

by:sunilramu
ID: 24794514
Thanks all.
how do you send periodic progress updates about percentage of work done. i am using a web based app deployed on a cluster. and i need to process the file once its uploaded which takes time. i cant have user directed to another app server (becasue of clustering) by using ajax. is there anything like a staged response in servlets.

0
 
LVL 92

Expert Comment

by:objects
ID: 24799490
sounds like you need sticky session to ensure the progress requests go to the same server
0
 
LVL 7

Expert Comment

by:nikhilmenon
ID: 24800827
I don't think there are staged responses as such in servlets. But you could logically implement this in a different way. Consider the following example of how you can handle your communication, keeping in mind a new thread of execution handles each request at the servlet:

Client: Sends HTTP request containing file to be uploaded

Servlet: Begins saving the file onto the server and responds with a "began download"

Client: Sends a periodic progress request

Servlet: Checks the progress (which may be set in a servlet class variable as the upload happens)and returns the same as a response.

(This continues a while till it is complete. And note that the servlet is continuously receiving the file in the process)

Client: Sends a periodic progress request

Servlet: Sends response which says "Upload complete. Processing."

(This continues till processing is done)

Client: Sends a periodic progress request

Servlet: Responds with the result of processing.

IMHO, this could be an alternative to a single request that receives the response once the processing is complete (that single request could time out if a response is not received within a set amount of time).

You could obviously refine this to prevent too much bandwidth overhead by minimizing the number of "progress requests". This could be done by responding with an approximate time to completion so the next request happens only after that duration.
0
 

Author Comment

by:sunilramu
ID: 24803344
nikhilmenon i like your idea.
Savant sticky sessions is not an option atleast as of yet.
has anyone familiar with or worked with Pushlets. this came up when i was looking up for more information.

thank you all.
0
 

Author Comment

by:sunilramu
ID: 24803375
nikhilmenon i like your idea. problem is that it will not work on cluster envt. unless status is maintained on database.
0
 
LVL 7

Expert Comment

by:nikhilmenon
ID: 24804244
Cookies might be an option. The cookie here containing the identifier for which particular server is handling the request from this client.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupNoAdj 7 84
Systems talking to each other 5 123
what is the difference between "sudo su" and "su - root" 6 102
Java Server Faces parameter pass? 6 37
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now