Performance bottleneck in JSON web services in Liferay 6.0.x
Community Blogs April 23, 2013 By Kan Zhang
There is one performance bottleneck in JSON web services in Liferay 6.0.x: JSONServiceAction class is loading service class per request.
When doing a load test on the Liferay JSON web services (Example below), the performance is bad.
In JSONServiceAction.getJSON() method:
On each of the request, the above code will load the service class based on the serviceClassName request parameter.
But the classloader.loadClass is a synchronized method, it becomes a performance bottleneck.
The project I was working on about two years ago only requires to access a certain set of JSON services. My strategy was to preload the service classes into a cache to avoid runtime class loading.
In Liferay ext plugin:
1. Create ServiceCacheUtil class:
2. create CustomJSONServlet. This allows me to configure the list of service classes to preload in tunnel-web's web.xml and to use the CustomJSONServiceAction (see step 4) class.
3. Customize web.xml in tunnel-web to use the CustomJSONServlet:
4. create a CustomJSONServiceAction which extends JSONServiceAction:
5. You will need to do the same steps above in your custom portlet if you have a Service Builder generated custom JSON service in your portlet.
Note: The issue already got resolved in Liferay 6.1.x using @JSONWebService anotation. The @JSONWebService anotated services will be registered in the JSONWebServiceActionsManager to avoid runtime classloading.
sShow or hide me with the buttons above.