We have java7 based a google app engine application. For some report generation process, we are already using an external service in AWS. This external service is based on spring and it is deployed on tomcat7 instance.
We are consuming this external service's REST API's from gae app and getting output from it. Recently we needed to parallelize this report generation task using URLFetch.
I am initiating my 12 POST requests at the same time then trying to collect results using URLFetch. (I am using same external service url for all requests)
But tomcat only receives 2 request at the same time and this is creating a bottleneck for us.
What may be limiting tomcat so it can only process 2 request at the same time?
- Is there anything configure on spring on external service?
- Is there anything to configure on tomcat?
- Is there anything to configure on google app engine?
Here you can find the request and collect part of code, for your reference.
URLFetchService fetcher = URLFetchServiceFactory.getURLFetchService();
FetchOptions fetchOptions = FetchOptions.Builder.withDefaults();
fetchOptions.doNotValidateCertificate();
fetchOptions.setDeadline(60d);
/* Initiate requests */
ArrayList<Future<HTTPResponse>> asyncResponses = new ArrayList<Future<HTTPResponse>>();
for(int i=startPage;i<(endPage+1);i++){
/* Create list of parameters to pass wkhtmltoPDF */
Map<String, Object> map = new HashMap<String, Object>();
map.put("parameters", parameters);
targetUrl = referer + "?viewMode=export&subjectId="+ subjectId +"&page=" + i;
map.put("targetUrl", targetUrl);
Gson gson = new Gson();
String data = gson.toJson(map);
URL serviceUrl = new URL(EXS_SERVER_URL+"/wkhtmltopdf");
HTTPRequest request = new HTTPRequest(serviceUrl, HTTPMethod.POST, fetchOptions);
HTTPHeader header = new HTTPHeader("Content-Type", "application/json; charset=UTF-8");
request.setHeader(header);
request.setPayload(data.getBytes("UTF-8"));
Future<HTTPResponse> responseFuture = fetcher.fetchAsync(request);
asyncResponses.add(responseFuture);
}
/* collect responses */
ArrayList<Integer> responseCodes = new ArrayList<Integer>();
for(int i=0;i<asyncResponses.size();i++){
Future<HTTPResponse> serviceResponse = null;
try {
serviceResponse = asyncResponses.get(i);
int responseCode = serviceResponse.get(59, TimeUnit.SECONDS).getResponseCode();
responseCodes.add(responseCode);
byte[] pdfBuffer = serviceResponse.get(59, TimeUnit.SECONDS).getContent();
if (pdfBuffer != null){
PdfReader page = new PdfReader(pdfBuffer);
copy.addDocument(page);
}
} catch (Exception e) {
e.printStackTrace();
}
}