10Oct/070
Transformaciones XSL (II): ¿Cuanto más rápidas son ahora?
En la anterior entrega se realizaron una serie de mediciones rápidas que indicaban una importante mejora mediante el uso de Translets. Una vez que la prueba de concepto ha sido superada, el siguiente paso es evaluar el rendimiento de los translets cuando se realizan un gran numero de peticiones concurrentes.
Como se puede ver en la siguiente gráfica, los tiempos medios de respuesta obtenidos cuando se utiliza la versión compilada de las transformaciones XSL, son un 100% más rápidos que su equivalente interpretativa y lo que es más importante, son lineales al número de peticiones concurrentes llevadas a cabo.
El siguiente código empleado durante esta simulación es el siguiente:
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.util.Properties; import javax.xml.transform.stream.StreamSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; public class simple { private static final String keyTransformerFactory = "javax.xml.transform.TransformerFactory"; private static final String xmlFileName = "simple.xml"; private static final String xslFileName = "simple.xsl"; private static final String outFileName = "simple.out."; /** * @param args */ public static void main(String[] args) { long t0, t1; for (int i = 0; i < 50;i++) { doInThread(); } t0 = System.currentTimeMillis(); doTransform(getTransletTransformer(), xslFileName, xmlFileName, outFileName); t1 = System.currentTimeMillis(); System.out.println((t1 - t0)); } public static void doInThread() { (new Thread() { public void run() { long t0, t1; t0 = System.currentTimeMillis(); doTransform(getInterpretativeTransformer(), xslFileName, xmlFileName, outFileName); t1 = System.currentTimeMillis(); System.out.println((t1 - t0)); } }).start(); } public static TransformerFactory getTransletTransformer() { // Set the TransformerFactory system property. // Note: For more flexibility, load properties from a properties file. String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; Properties props = System.getProperties(); props.put(keyTransformerFactory, value); System.setProperties(props); // 1. Instantiate a TransformerFactory. TransformerFactory tFactory = TransformerFactory.newInstance(); // tFactory.setAttribute("debug", Boolean.TRUE); tFactory.setAttribute("generate-translet", Boolean.TRUE); tFactory.setAttribute("auto-translet", Boolean.TRUE); tFactory.setAttribute("destination-directory", "translets"); return tFactory; } public static TransformerFactory getInterpretativeTransformer() { // Set the TransformerFactory system property. // Note: For more flexibility, load properties from a properties file. String value = "org.apache.xalan.processor.TransformerFactoryImpl"; Properties props = System.getProperties(); props.put(keyTransformerFactory, value); System.setProperties(props); // 1. Instantiate a TransformerFactory. TransformerFactory tFactory = TransformerFactory.newInstance(); return tFactory; } public static void doTransform(TransformerFactory tFactory, String xslFile, String xmlFile, String outFile) { //System.out.println(tFactory.getClass().toString()); javax.xml.transform.Transformer transformer; try { // 2. Use the TransformerFactory to process the stylesheet Source // and generate a Transformer. transformer = tFactory.newTransformer(new StreamSource(xslFile)); // 3. Use the Transformer to transform an XML Source and send the // output to a Result object. transformer.transform(new StreamSource(xmlFile), new StreamResult( new FileOutputStream(outFile + Thread.currentThread().getId()))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (TransformerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Imprimir este artículo
Comentarios (0)
Trackbacks (0)
( suscribirse a los comentarios de esta entrada )
Aún no hay trackbacks.





