Scott,
On Wed, Dec 29, 2010 at 4:53 PM, <[email protected]> wrote:
> Since we added new servers, users have been complaining that the Perl scripts
> are taking a lot longer. After a lot of logging and testing, I discovered
> that the Inline::Java module is the bottleneck. Even though the threads
> appear to be running in parallel, the actual time taken is approximately
> equal to single-threaded performance. I.e.
>
> Time to run Java threads = (# threads) x (time to run one Java thread)
I don't see that behaviour with a simple program (t.pl):
use Inline (
Java => 'DATA',
SHARED_JVM => 1,
PORT => 17891,
) ;
Inline::Java::capture_JVM() ; # Kill JVM on exit
my $nb = 5 ;
for (my $i = 0 ; $i < $nb ; $i++){
if (! fork){
print "start $i\n" ;
Inline::Java::reconnect_JVM() ;
test->sleep() ;
print "end $i\n" ;
exit ;
}
}
for (my $i = 0 ; $i < $nb ; $i++){
wait() ;
}
__DATA__
__Java__
class test {
public static void sleep() throws InterruptedException {
Thread.sleep(5000) ;
}
}
$ time perl t.pl
start 0
start 1
start 2
start 3
start 4
end 0
end 1
end 3
end 2
end 4
real 0m5.264s
user 0m0.198s
sys 0m0.102s
> Looking at the implementation of Inline::Java, I can see that a large # of
> the Java methods are declared as synchronized. I.e.
>
> cd ~/.cpan/build/Inline-Java-0.52
> find . -name '*.java' -exec grep synchronize {} \;
>
> It appears that when calling Java methods using the module, only one method
> can only be run at any given time, forcing single-threaded performance. The
> vast majority of time in my Perl script is spent waiting for the application
> server Java methods to respond, thus this synchronization is the key
> bottleneck.
Calling Java from Perl is not synchonized, but if you call back into
Perl from Java ("callbacks") those calls are synchronized. Is that
what your code is doing?
Patrick
--
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada