Blogs
Issue:
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.
| http://<IP_ADDRESS>:8080/tunnel-web/secure/json?serviceClassName=com.liferay.portal.service.CountryServiceUtil&serviceMethodName=getCountries |
Cause:
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.
Solution:
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.

