Performance bottleneck in JSON web services in Liferay 6.0.x

This issue is addressed in Liferay 6.1.x. It only affacts Liferay 6.0.x.

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.

Warning: The above code is not tested. I have implemented it two years ago but unfortunately I do not have that code any more. The above code I wrote is based on my memory - Use at your own risk.

 

博客
Any one know how to use Gist in blog? I have read James Falkner's blog about how to use Gist:
---------------
You can include gists (code snippets) using the 'Embed' option, and cutting/pasting the necessary javascript. This is the only kind of js allowed in your blog.
---------------
But I didn't find 'Embed' option in the editor....
Kan - go to gist.github.com, cut/paste your code, click 'Create Public Gist', then you will see a 'Embed this Gist' option on the left, simply cut and paste the code (it starts with a <script> tag) into your Liferay blog, by first switching to the "Source" view of your blog (click the "Source" button), cut and paste, then switch back and beautify emoticon
James - Looks like all the indents in Gist are not displaying properly because of the following CSS on liferay site:
pre {
white-space: pre-line;
}
-------
Fixed by inserting the following CSS in "Source" view:
<style type="text/css">
pre {
white-space: pre !important;
}
</style>