I am using spring MVC model in my project. In which controller get request from some some thired party application. Controller get 20 request per sec. Code look like this
@Controller
@RequestMapping("/action")
public class FrontController{
@AutoWired
private CommonService commonService;
(First Code)
@RequestMappint("/save")
public String saveData(@PathParam("id")String did){
List<String, Object> map = commonService.getVmn(did);
CallReporting callReporting = new CallReporting();
callReporting.setName(map.get("name"));
so---on (have 15 field)
commonService.save(callReporting);
}
return "1";
}
This code is working fine but some time if mysql is busy then it takes time to return the value to calling application. So I droped the idea and start Async communication.
(Second Code)
@RequestMappint("/save")
public String saveData(@PathParam("id")String did){
Thread thread = new Thread(new Runnable(){
List<String, Object> map = commonService.getVmn(did);
CallReporting callReporting = new CallReporting();
callReporting.setName(map.get("name"));
so---on (have 15 field)
commonService.save(callReporting);
});
}
return "1";
}
I started using the code something like this. So that calling party can get the response immediately(reduce the response time) and later on my application continue to work. But in First code i test the load with JMeter(20 req/sec ) and found it is working fine with cpu load(3%). But in second code with same load cpu load is going to more than 100%.Than i started using the ThreadPoolTaskExecutor with below configuration.
@AutoWired
private ThreadPoolTaskExecutor executor;
@RequestMappint("/save")
public String saveData(@PathParam("id")String did){
//Assume this code is in MyRunnableWorker Class
List<String, Object> map = commonService.getVmn(did);
CallReporting callReporting = new CallReporting();
callReporting.setName(map.get("name"));
so---on (have 15 field)
commonService.save(callReporting);
MyRunnableWorker worker = new MyRunnableWorker();
executor.execute(worker)
return "1";
}
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="corePoolSize" value="50" />
<property name="maxPoolSize" value="100" />
<property name="keep-alive" value="10" />
<property name="queueCapacity" value="200" />
</bean>
but found the same result. Whats wrong with code can somebody suggest me. One important thing when i test with Jmeter in stage envorment then load is moving between 30% to 70%.. But in production server it is always around 100%. It is java consuming 100% other process is quite low. Production machine haveing linux OS. hexacore processer having 128 GB RAM. Can some one tell me what to do.