Hi everyone,
I have done a simple test on jndi lookup (on a separated client). I just really upset that the average time for the lookup is around 400 ms (local machine) and 500ms (remote machine).
I just wonder is there something wrong with my performance optimization ?
Following is the code of the client
public static void main(String[] args) { // TODO Auto-generated method stub if (System.getSecurityManager() == null) System.setSecurityManager(new RMISecurityManager()); Calendar c = Calendar.getInstance(); Properties env = new Properties(); env.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); //switch to 'localhost:1100' for performance comparison env.setProperty("java.naming.provider.url", "192.168.1.2:1099"); env.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming"); try{ long start = System.currentTimeMillis(); Context ctx = new InitialContext(env); Object ref = ctx.lookup("BBean/remote"); long end = System.currentTimeMillis(); long el = end - start; System.out.println("elapse(ms): " + el); } catch(NamingException e){ e.printStackTrace(); } }
JNDI initial context connection creation time is most of the time, and may largely be net or classloading overhead. Cache the initial context.
On the same JVM, you don't need to connect remotely, and should be quite fast.