http://www.perlmonks.org?node_id=1021294

allyc has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks,

I have a strange issue and I am not sure if anyone has seen anything similar before. I have a web app running on windows and I am porting it to mod_perl to give it a massive performance boost.

I am all but done, however I am hitting an issue with the JSON module when the service is put under load and it is puzzling me something stupid.

I make quite extensive use of JSON::true and JSON::false in my application, but it seems that under load in mod_perl it can in some cases return null instead of true or false.

I have run a simple script which proves the point I am having. This just creates a simple data structure including a JSON::true and then encodes it and prints the results.

In CGI mode this works fine and in mod_perl it works *most* of the time. When placed under load with apache bench the result of success some times comes out as null when it should say true. This breaks my application and is the only thing that is stopping me going forward with mod_perl. This is the test script I use;

use JSON; my $json = JSON->new(); $json->convert_blessed(1); $json->allow_blessed(1); my $data = { success => JSON::true, test=>'Hello' }; print "Content-type: text/html\n\n"; print $json->encode($data);

This prints out the following all of the time in cgi mode but only some of the time in mod_perl. {"success":true,"test":"Hello"}

An example from Apache Bench shows the following when I have 50 concurrent users requesting 1000 pages.

LOG: header received: HTTP/1.1 200 Date: Fri, 01 Mar 2013 16:09:11 Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ Connection: Content-Type: text/html {"success":true,"test":"Hello"} LOG: header received: HTTP/1.1 200 OK Date: Fri, 01 Mar 2013 16:09:11 GMT Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ +v5.16.1 Connection: close Content-Type: text/html {"success":null,"test":"Hello"} LOG: header received: HTTP/1.1 200 OK Date: Fri, 01 Mar 2013 16:09:11 GMT Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ +v5.16.1 Connection: close Content-Type: text/html {"success":null,"test":"Hello"} LOG: header received: HTTP/1.1 200 OK Date: Fri, 01 Mar 2013 16:09:11 GMT Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ +v5.16.1 Connection: close Content-Type: text/html {"success":null,"test":"Hello"} LOG: header received: HTTP/1.1 200 OK Date: Fri, 01 Mar 2013 16:09:11 GMT Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ +v5.16.1 Connection: close Content-Type: text/html {"success":true,"test":"Hello"} LOG: header received: HTTP/1.1 200 OK Date: Fri, 01 Mar 2013 16:09:11 GMT Server: Apache/2.2.23 (Win32) mod_auth_sspi/1.0.5 mod_perl/2.0.7 Perl/ +v5.16.1 Connection: close Content-Type: text/html {"success":true,"test":"Hello"}

As you can see some times the success value comes back as null and I have no idea why? I can only assume that there is an issue with JSON::XS in one of the threads within apache.

If I remove JSON::XS and use JSON::PP then the issue goes away and all of the bool values come back as expected however there is the big performance hit here so I do not see that as a solution.

I am currently running Apache 2.2.23 with mod_perl 2.0.7 and running ActivePerl v5.16.1. The JSON::XS module installed is the latest which is 2.23 and the JSON core is 2.53 which came with ActivePerl.

Has any one seen this behavior in the past or have any suggestions as to what could be causing this issue?

Many Thanks,
Alistair