Agilefreaks / schematron-wrapper

A ruby gem that wrappers various schematron implementations so they can be easily used in ruby
Mozilla Public License 2.0
4 stars 7 forks source link

Is it possible to prelaunch the JVM and service multiple requests? #8

Open mwlang opened 5 years ago

mwlang commented 5 years ago

First, thanks for this great wrapper around the Java schematron libraries. I was able to quickly set it up and validate schematron data against our XML documents.

But it's kind of slow to process each message and I traced the performance to launching the JVM in Schematron::Utils#execute_transform

image

2.52 seconds, 99.48% overall, just to fire up and run the transformation. My goal is to embed this in a Rails project and was wondering if it's possible to fire up the JVM when the Rails app starts and feed it all incoming requests to validate.

I'm not a Java expert, but am with Ruby and would be happy to code the PR necessary if its possible and some guidance offered on what has to change to make this work.

mwlang commented 5 years ago

I did a little research on Java to learn about optimizing JVM startup times.

This update is just to provide some more information on startup times. I'd still like to try to accomplish original request of one JVM for many calls.

With the default settings on this library, I get the following times running my schematron validation test:

real    0m2.367s
user    0m4.015s
sys 0m0.929s

By modifying #execute_transform to add -client and -dev flags (client fo linux, dev for osx), I greatly reduced start time as follows:

real    0m1.032s
user    0m1.390s
sys 0m0.257s

So even if not possible to start the JVM in the background and service multiple requests with one instance, we can definitely speed things up greatly for the quick one-off calls as used by the wrapper.