Commit 81aed7c1 authored by afreyssin's avatar afreyssin
Browse files

Adds JNDI performance tests.

parent 0dcbfc09
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2013 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent D.T.
* Contributor(s):
*/
package jndi2.base;
import java.util.Hashtable;
import java.util.Random;
import javax.naming.Context;
import javax.naming.InitialContext;
import fr.dyade.aaa.agent.AgentServer;
import framework.TestCase;
/**
* Measures JNDI lookup and bind costs with many bindings in a unique context.
*/
public class Perf1 extends TestCase {
public final static int NbRegisteredObject = 10000;
public static void main(String[] args) {
new Perf1().run();
}
static void startServer() throws Exception {
AgentServer.init((short) 0, "./s0", null);
AgentServer.start();
Thread.sleep(1000L);
}
public void run() {
try {
startServer();
Thread.sleep(1000);
Hashtable properties = new Hashtable();
properties.put("java.naming.factory.initial", "fr.dyade.aaa.jndi2.client.NamingContextFactory");
properties.put("java.naming.factory.host", "localhost");
properties.put("java.naming.factory.port", "16600");
Context ctx = new InitialContext(properties);
long start, end;
Exception excep = null;
try {
start = System.nanoTime();
for (int i=0; i<NbRegisteredObject; i++)
ctx.bind("toto" + i, "hello#" + i);
end = System.nanoTime();
System.out.println("binding (ms) = " + ((end-start)/1000000L));
} catch (Exception exc) {
excep = exc;
exc.printStackTrace();
}
assertNull(excep);
if (excep != null) throw excep;
Random rand = new Random();
try {
start = System.nanoTime();
for (int i=0; i<100000; i++) {
String hello = (String) ctx.lookup("toto" + rand.nextInt(NbRegisteredObject));
}
end = System.nanoTime();
System.out.println("binding (ms) = " + ((end-start)/1000000L));
} catch (Exception exc) {
excep = exc;
exc.printStackTrace();
}
assertNull(excep);
if (excep != null) throw excep;
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
} finally {
AgentServer.stop();
endTest();
}
}
}
/*
* JORAM: Java(TM) Open Reliable Asynchronous Messaging
* Copyright (C) 2013 ScalAgent Distributed Technologies
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Initial developer(s): ScalAgent D.T.
* Contributor(s):
*/
package jndi2.base;
import java.util.Hashtable;
import java.util.Random;
import javax.naming.Context;
import javax.naming.InitialContext;
import fr.dyade.aaa.agent.AgentServer;
import framework.TestCase;
/**
* Measures JNDI lookup and bind costs with multiples contexts.
*/
public class Perf2 extends TestCase {
public final static int NbContext = 100;
public final static int NbRegisteredObject = 10000;
public static void main(String[] args) {
new Perf2().run();
}
static void startServer() throws Exception {
AgentServer.init((short) 0, "./s0", null);
AgentServer.start();
Thread.sleep(1000L);
}
public void run() {
try {
startServer();
Thread.sleep(1000);
Hashtable properties = new Hashtable();
properties.put("java.naming.factory.initial", "fr.dyade.aaa.jndi2.client.NamingContextFactory");
properties.put("java.naming.factory.host", "localhost");
properties.put("java.naming.factory.port", "16600");
Context ctx = new InitialContext(properties);
long start, end;
Exception excep = null;
try {
start = System.nanoTime();
for (int i=0; i<NbRegisteredObject; i++) {
if ((i%NbContext) == 0)
ctx.createSubcontext("/toto" + (i/NbContext));
ctx.bind("/toto" + (i/NbContext) + "/toto" + (i%NbContext), "hello#" + i);
}
end = System.nanoTime();
System.out.println("binding (ms) = " + ((end-start)/1000000L));
} catch (Exception exc) {
excep = exc;
exc.printStackTrace();
}
assertNull(excep);
if (excep != null) throw excep;
Random rand = new Random();
try {
start = System.nanoTime();
for (int i=0; i<100000; i++) {
String hello = (String) ctx.lookup("/toto" + rand.nextInt(NbContext) + "/toto" + rand.nextInt(NbRegisteredObject/NbContext));
}
end = System.nanoTime();
System.out.println("lookup (ms) = " + ((end-start)/1000000L));
} catch (Exception exc) {
excep = exc;
exc.printStackTrace();
}
assertNull(excep);
if (excep != null) throw excep;
} catch (Exception exc) {
exc.printStackTrace();
error(exc);
} finally {
AgentServer.stop();
endTest();
}
}
}
<?xml version="1.0"?>
<config>
<property name="Transaction" value="fr.dyade.aaa.ext.NGTransaction"/>
<property name="Transaction.SyncOnWrite" value="false"/>
<server id="0" name="s0" hostname="localhost">
<service class="fr.dyade.aaa.agent.AdminProxy" args="8090"/>
<service class="fr.dyade.aaa.jndi2.server.JndiServer" args="16600"/>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment