DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://issues.apache.org/bugzilla/show_bug.cgi?id=29980>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=29980 xslt multithreaded performance Summary: xslt multithreaded performance Product: XalanJ2 Version: 2.6 Platform: PC OS/Version: Linux Status: NEW Severity: Normal Priority: Other Component: org.apache.xalan.transformer AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] A program that uses a single stylesheet and multiple threads to transform documents uses significantly more (roughly 60%) cpu time when the transform is not synchronized. This results in confusing performance characteristics for threaded applications (on a 2 cpu box, my application had a slight performance degradation when I increased from 1 thread to 2 and performance degraded significantly when the number of threads was greater than the number of cpus). The inlined TransformerThread class can be used to demonstrate this behavior. I ran java version "1.4.2_04" with the options '-server' and "- Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerF actoryImpl". The TransformerThread program takes a stylesheet file as its first argument (I've inlined xform.xsl which I used) and 'true'|'false' as its second argument to specify whether or not to synchronize the transform code block. TransformerThread class: import java.io.*; import java.util.*; import javax.xml.transform.*; import javax.xml.transform.stream.*; public class TransformerThread extends Thread { Templates templates; boolean synchronize; public static void main(String []args) throws TransformerConfigurationException { Templates templates = TransformerFactory.newInstance().newTemplates( new StreamSource(new File(args[0])) ); Thread []threads = new Thread[5]; for (int i=0; i<threads.length; ++i) { threads[i] = new TransformerThread( templates, "thread-"+String.valueOf(i+1), Boolean.valueOf(args[1]).booleanValue() ); threads[i].start(); } System.out.println("Threads kicked off"); System.out.flush(); for (int i=0; i<threads.length; ++i) { try { threads[i].join(); } catch (InterruptedException e) { /* ignore */} } } public TransformerThread(Templates templates, String name, boolean synchronize) { super(name); this.templates = templates; this.synchronize = synchronize; } public void run() { byte []bytes = new String( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<foo>\n" + " <property name=\"bar\">bar-value</property>\n" + " <property name=\"bar\">bar-value</property>\n" + " <property name=\"baz\">baz-value</property>\n" + "</foo>" ).getBytes(); for (int i=0; i<2500; ++i) { try { StreamResult result = new StreamResult(new ByteArrayOutputStream ()); if (synchronize) { synchronized (templates) { templates.newTransformer().transform( new StreamSource(new ByteArrayInputStream(bytes)), result ); } } else { templates.newTransformer().transform( new StreamSource(new ByteArrayInputStream(bytes)), result ); } } catch(TransformerException e) { e.printStackTrace(); } } System.out.println("done: " + getName()); } } xform.xsl: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/foo"> <foo> <xsl:for-each select="[EMAIL PROTECTED] != 'baz']"> <xsl:copy-of select="."/> </xsl:for-each> </foo> </xsl:template> </xsl:stylesheet> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
