Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 29419 invoked from network); 16 Oct 2007 09:29:26 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Oct 2007 09:29:26 -0000 Received: (qmail 9663 invoked by uid 500); 16 Oct 2007 09:29:12 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 9644 invoked by uid 500); 16 Oct 2007 09:29:12 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 9635 invoked by uid 99); 16 Oct 2007 09:29:12 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2007 02:29:12 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of smallsmallorgan@gmail.com designates 72.14.214.234 as permitted sender) Received: from [72.14.214.234] (HELO hu-out-0506.google.com) (72.14.214.234) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 16 Oct 2007 09:29:15 +0000 Received: by hu-out-0506.google.com with SMTP id 27so1808448hub for ; Tue, 16 Oct 2007 02:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; bh=UqqgGhg3xz9ahWDy6th8IiaDnw5jzZ+NElPLDbqkGio=; b=QtF6O6N3tsZGyc7a+F2PGClUcjZIPKQdifTTyhPuVmxH8XJ+VKhxr3JV2CvcuGZjoeZtmJyxuVy/30vAlcabBe2TQAxeAzfXREG+cRgY21KGRcFu/tPMZOaFTtsytnipnvOXJKofDCPHM9tCPIwsbm46f0z2axgM58QC7wHDnzA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=oCOK4A4ZUOVAxD2cskk5vNIrgM2zSc/4JgXSYa0oZmxfQWQA5xfa1GCKtExfoXJ+MN3Y/YXC8K5z8e7OEJeZST6sKpOd1T/qc7A6Tir0AZjWrHfog8L27E/op5UdumUgY79xUKY3rsZP6rbmoMj+peyOzDkjQKbOdGooog9p8lw= Received: by 10.140.193.16 with SMTP id q16mr3345654rvf.1192526927948; Tue, 16 Oct 2007 02:28:47 -0700 (PDT) Received: by 10.65.61.12 with HTTP; Tue, 16 Oct 2007 02:28:47 -0700 (PDT) Message-ID: <473c46620710160228k4eb36680vb7610028b9fe140a@mail.gmail.com> Date: Tue, 16 Oct 2007 17:28:47 +0800 From: "Spark Shen" To: dev@harmony.apache.org Subject: Re: [classlib][performance] InitialContext searches for jndi.properties every contruction time(Harmony-4942) In-Reply-To: <47146F43.6070901@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_16912_7334688.1192526927844" References: <47146F43.6070901@gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_16912_7334688.1192526927844 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi I read your comments in http://issues.apache.org/jira/browse/HARMONY-4942. And I agree with you different apps context uses different classloader for loading different properties as you said. I did not catch you is 'I'm not sure how ri do this'. I just want to clarify my understanding here: You are not quite sure about how RI handle modification to the same jndi.properties file in different classloaders. And in your post here, you proved that, indeed different classloaders in RI will overwrite each other. And I think we'd better follow RI, since many application servers are already running stably on it. 2007/10/16, Regis : > > Hi, > I survey the issue Harmony-4942, found the Harmony's behavior of finding > "jndi.properties" file is not the same as ri's: > Harmony re-search the whole CLASSPATH every construction time, while ri > just search once when using a classloader to > find the file at first time. The following code prove it: > > =============begin============= > > URL url = new File("test1").toURL(); > URLClassLoader cltest1 = new URLClassLoader(new URL[] { url > }, > Thread.currentThread().getContextClassLoader()); > Thread test1 = new Thread(new Runnable() { > > public void run() { > try { > System.out.println("test1 classloader" > + Thread.currentThread() > .getContextClassLoader()); > FileOutputStream fos = new FileOutputStream( > "test1/jndi.properties"); > PrintStream ps = new PrintStream(fos); > ps > > .println(" > java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory"); > > ps.println("java.naming.provider.url=http://test1"); > ps.close(); > > InitialContext context = new InitialContext(); > System.out.println("test1.context= " + > context); > System.out.println("test1.context.env=" > + context.getEnvironment()); > > File file = new File("test1/jndi.properties"); > file.delete(); > > // create new properties file with different > values > fos = new FileOutputStream( > "test1/jndi.properties"); > ps = new PrintStream(fos); > ps > > .println(" > java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory"); > > ps.println("java.naming.provider.url=http://test1.new"); > ps.close(); > > context = new InitialContext(); > System.out.println("test1.new.context=" + > context); > System.out.println("test1.new.context.env=" > + context.getEnvironment()); > > } catch (Exception e) { > e.printStackTrace(); > } > } > > }); > // use different classloader > test1.setContextClassLoader(cltest1); > > test1.start(); > > url = new File("test2").toURL(); > URLClassLoader clSrc = new URLClassLoader(new URL[] { url > }, Thread > .currentThread().getContextClassLoader()); > > Thread test2 = new Thread(new Runnable() { > > public void run() { > try { > System.out.println("test2 classloader" > + Thread.currentThread() > .getContextClassLoader()); > FileOutputStream fos = new FileOutputStream( > "test2/jndi.properties"); > PrintStream ps = new PrintStream(fos); > ps > > .println(" > java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory"); > > ps.println("java.naming.provider.url=http://test2"); > ps.close(); > InitialContext context = new InitialContext(); > System.out.println("test2.context= " + > context); > System.out.println("test2.context.env=" > + context.getEnvironment()); > } catch (Exception e) { > e.printStackTrace(); > } > } > > }); > > // use different classloader > test2.setContextClassLoader(clSrc); > test2.start(); > > ===================end================= > (I slightly modify MyDefaultInitialContextFactory, add environment > values to MyInitialContext after initial) > > the output is below, using jre1.6.0: > > ============start output=============== > > test1 classloaderjava.net.URLClassLoader@42e816 > test1.context= javax.naming.InitialContext@60aeb0 > > test1.context.env={java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory > , > java.naming.provider.url=http://test1} > test1.new.context=javax.naming.InitialContext@16caf43 > > test1.new.context.env={java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory > , > java.naming.provider.url=http://test1} > test2 classloaderjava.net.URLClassLoader@8813f2 > test2.context= javax.naming.InitialContext@1d58aae > > test2.context.env={java.naming.factory.initial=regis.jndi.MyDefaultInitialContextFactory > , > java.naming.provider.url=http://test2} > > =============end output================= > > So under same classloader, ri just search property file once. > > In harmony we can use a map to hold property values for each classloader > to avoid search at every construction time. > But i found Harmony is still slower than ri at first time to constuct > InitialContext object, the most time is consumed at > org.apache.harmony.jndi.internal.EnvironmentReader line 233: > p.load(is); As for the performance issue in Properties.java, I think may be it's caused by lack of cache. I am interested, and will look into the issue. BTW, did you report a seperate JIRA for it? Then i write some sample code to test performance of Properties.load(): > > Properties pro = new Properties(); > URL url = new > > > URL("jar:file:/home/bahamut/harmony/trunk/deploy/jdk/jre/lib/boot/jndi.jar!/jndi.properties"); > InputStream in = url.openStream(); > long start = System.currentTimeMillis(); > pro.load(in); > long end = System.currentTimeMillis(); > System.out.println("time: " + (end - start)); > in.close(); > > pro = new Properties(); > url = new > > > URL("jar:file:/home/bahamut/harmony/trunk/deploy/jdk/jre/lib/boot/jndi.jar!/jndi.properties"); > in = url.openStream(); > start = System.currentTimeMillis(); > pro.load(in); > end = System.currentTimeMillis(); > System.out.println("time: " + (end - start)); > in.close(); > > output of ri: > time: 1 > time: 0 > > output of harmony: > time: 231 > time: 1 > > Harmony is slower than ri *two hundred* times!! > in above test, property file is in jndi.jar about 230k, if not in jar > file, the time of harmony and ri are very close, > so i think there must be some problems of archive module. Is it because > of we using different algorithm with ri, > or our implementation has bugs? > > Best Regards, > Regis. > -- Spark Shen China Software Development Lab, IBM ------=_Part_16912_7334688.1192526927844--