[ http://issues.apache.org/jira/browse/XALANJ-1905?page=all ]
Brian Minchau updated XALANJ-1905:
----------------------------------
Version: 2.6
(was: Latest Development Code)
> xslt multithreaded performance
> ------------------------------
>
> Key: XALANJ-1905
> URL: http://issues.apache.org/jira/browse/XALANJ-1905
> Project: XalanJ2
> Type: Bug
> Components: transformation, Xalan-interpretive
> Versions: 2.6
> Environment: Operating System: Linux
> Platform: PC
> Reporter: Stephen
> Assignee: Xalan Developers Mailing List
>
> 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>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]