@Michael: Thanks for your suggestion. Can you explain me why do you think, it's a TCP issue? I was assuming may be the way I am using RestTemplate in my code might not be right and that's why it might be resulting in TIME_WAIT connections a lot on the machine where I have my code deployed which makes Http Call to my RestService? In the company I am working here, they have their own Parent POM in which they have spring dependency, the latest I can get for Spring is 3.2.8: I am not sure whether Spring 3.2.8 uses new version of HttpClient or not. I did check the first github link you provided but I was not able to find "ivy.xml" file in 3.2.x branch so cannot confirm that. May be you know some other way to confirm that. I can use Spring 3.2.8 version max here. And also, do you see any issues with the way I am using RestTemplate here, I am just using default way of making HttpClient calls, may be I need to have some sort of extra parameter to resolve this issue? Are there anything I need to set while making RestTemplate calls like "Connection: close" or "keep-alive" anything like this? And also do you think the way I am using RestTemplate will reuse/pool my client connections or not?
@Stefan: I am using RestTemplate in default way as shown in my above code. I am assuming, it will be reusing/pooling my connections right? I did google the issue and I found out lot of things, like lowering down the "tcp_fin_timeout" value from 60 to 30 and some other stuff as mentioned here in this article: http://www.fromdual.com/huge-amount-of-time-wait-connections But I was trying to confirm whether it might be related to how I am using RestTemplate or it is a OS issue? If I can confirm it's an OS issue, then I will look into that and if let's say the way I am using RestTemplate is not right, then I might try improving my code to see whether the problem goes away or not. I am thinking may be the way I am using RestTemplate is not right? May be I need to have "keep-alive" options on? On Thu, Jun 4, 2015 at 12:52 PM, Stefan Magnus Landrø < [email protected]> wrote: > I presume you are reusing/pooling your client connections, right? > Also - you could tune your OS to shutdown connections faster. You can > easily google you issue. > > Stefan > > 2015-06-04 17:51 GMT+02:00 Check Peck <[email protected]>: > > > I am using Spring RestTemplate to make a HTTP Calls to my RestService. I > am > > using spring framework 3.1.1 version of RestTemplate. I cannot upgrade > this > > since that's what we are using in our company. > > > > Now machine which is running my code (which uses RestTemplate) to make > call > > to my RestService, I see lot of TIME_WAIT connections opened on that > > particular machine? > > > > - Is there any reason why it happens with RestTemplate or the way I am > > using it? > > - Also, what is the connection between TIME_WAIT and HTTP Client calls to > > my RestService? I am not able to understand this as well. Does HTTP Calls > > has any significance on TIME_WAIT? There might be some theoretical > > explanation for this I guess. > > > > Below is how I am using RestTemplate in my code base: > > > > public class DataClient implements Client { > > > > private final RestTemplate restTemplate = new RestTemplate(); > > private ExecutorService executor = > > Executors.newFixedThreadPool(10); > > > > // for synchronous call > > @Override > > public String getSyncData(DataKey key) { > > String response = null; > > Future<String> handler = null; > > try { > > handler = getAsyncData(key); > > response = handler.get(key.getTimeout(), > > TimeUnit.MILLISECONDS); > > } catch (TimeoutException ex) { > > // log an exception > > handler.cancel(true); > > } catch (Exception ex) { > > // log an exception > > } > > > > return response; > > } > > > > // for asynchronous call > > @Override > > public Future<String> getAsyncData(DataKey key) { > > Future<String> future = null; > > > > try { > > Task task = new Task(key, restTemplate); > > future = executor.submit(task); > > } catch (Exception ex) { > > // log an exception > > } > > > > return future; > > } > > } > > > > And below is my simple Task class > > > > class Task implements Callable<String> { > > > > private final RestTemplate restTemplate; > > private final DataKey key; > > > > public Task(DataKey key, RestTemplate restTemplate) { > > this.key = key; > > this.restTemplate = restTemplate; > > } > > > > public String call() throws Exception { > > ResponseEntity<String> response = null; > > > > String url = "some_url_created_by_using_key"; > > > > // handling all try catch here > > response = restTemplate.exchange(url, HttpMethod.GET, null, > > String.class); > > > > return response.getBody(); > > } > > } > > > > And here is netstat details on my box which is running my code to make > HTTP > > Calls to my RestService. I am always seeing very high number of TIME_WAIT > > connections. > > > > 72 ESTABLISHED > > 2 FIN_WAIT1 > > 17 LISTEN > > 3405 TIME_WAIT > > > > > > -- > BEKK Open > http://open.bekk.no > > TesTcl - a unit test framework for iRules > http://testcl.com >
