I'm doing my first Java EE web application using glassfish and netbeans. When I create a unit test that requires the embedded EJB Container it can take around 30s to load. I thought that was completely understandable since it's "mimicking" the glassfish server. But then I came across this article from Adam Bien where it says:
The entire test, with booting the container, takes on my machine about 5 seconds.
http://www.adam-bien.com/roller/abien/entry/embedding_ejb_3_1_container
So I have to assume something is not configured right. I'm running Linux Mint 12, my project is using a MySQL database and my PC is 2Ghz dual core, 4 GB ram. Most everything is using the default settings from the netbeans install. (I did order a new processor that will move the CPU Benchmark from 1700 to 7800 according to cpubenchmark.net)
What can I do to improve the speed of booting the Embedded EJB Container?
while looking at the output, the main culprate seems to be:
org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA
Here is the full output:
Jan 9, 2012 5:01:57 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
Jan 9, 2012 5:01:59 PM org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
Jan 9, 2012 5:02:00 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (1,476ms), startup services(2,053ms), total(3,529ms)
Jan 9, 2012 5:02:00 PM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run INFO: JMXStartupService: JMXConnector system is disabled, skipping.
Jan 9, 2012 5:02:02 PM org.glassfish.admin.mbeanserver.JMXStartupService shutdown INFO: JMXStartupService and JMXConnectors have been shut down.
Jan 9, 2012 5:02:02 PM com.sun.enterprise.v3.server.AppServerStartup stop INFO: Shutdown procedure finished
Jan 9, 2012 5:02:02 PM AppServerStartup run INFO: [Thread[GlassFish Kernel Main Thread,5,main]] exiting
Jan 9, 2012 5:02:02 PM org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
Jan 9, 2012 5:02:02 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: GlassFish Server Open Source Edition 3.1.1 (12) startup time : Embedded (5,874ms), startup services(150ms), total(6,024ms)
Jan 9, 2012 5:02:02 PM org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run INFO: JMXStartupService: JMXConnector system is disabled, skipping.
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.EJBContainerProviderImpl skipJar INFO: ... skipping entry with a Manifest file with a special attribute: glassfish-embedded-static-shell.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding EJB module to ScatteredArchive classes
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive mysql-connector-java-5.1.13-bin.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive commons-codec-1.6.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive commons-codec-1.6-bin.zip
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive ant.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive primefaces-3.0.RC2.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive ant-junit.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive log4j-1.2.15.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive classes
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.DeploymentElement getOrCreateApplication INFO: [DeploymentElement] adding library to ScatteredArchive junit-4.8.2.jar
Jan 9, 2012 5:02:03 PM org.glassfish.ejb.embedded.EJBContainerImpl deploy INFO: [EJBContainerImpl] Deploying app: org.glassfish.embeddable.archive.ScatteredArchive@1ebafda6
Jan 9, 2012 5:02:08 PM org.hibernate.validator.util.Version <clinit> INFO: Hibernate Validator 4.1.0.Final
Jan 9, 2012 5:02:09 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle <init> INFO: SEC1002: Security Manager is OFF.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle onInitialization INFO: SEC1010: Entering Security Startup Service
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.PolicyLoader loadPolicy INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [admin-realm] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [file] of classtype [com.sun.enterprise.security.auth.realm.file.FileRealm] successfully created.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.auth.realm.Realm doInstantiate INFO: SEC1115: Realm [certificate] of classtype [com.sun.enterprise.security.auth.realm.certificate.CertificateRealm] successfully created.
Jan 9, 2012 5:02:15 PM com.sun.enterprise.security.SecurityLifecycle onInitialization INFO: SEC1011: Security Service(s) Started Successfully
Jan 9, 2012 5:02:17 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
Jan 9, 2012 5:02:26 PM org.hibernate.validator.engine.resolver.DefaultTraversableResolver detectJPA INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
Jan 9, 2012 5:02:26 PM org.eclipse.persistence.session.file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU INFO: EclipseLink, version: Eclipse Persistence Services - 2.3.0.v20110604-r9504
Jan 9, 2012 5:02:29 PM org.eclipse.persistence.session.file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU INFO: file:/tmp/gfembed2576733372934037196tmp/applications/classes/_REMPU login successful
...
Thanks
You could try another EJBContainer impl.
The test time of the OpenEJB Embedded EJBContainer is in the 1 second range. It supports the GlassFish descriptors -- we use them instead of our own when we run the Java EE TCK as we're too lazy to write the several thousand descriptors we would need and the TCK already comes with complete GlassFish descriptors.
Alternatively, maybe try a different approach entirely.
For a more unit test style maybe check this out: https://stackoverflow.com/a/8716630/190816 I.e. build the app in the test case and throw in some mocking as needed.
Here is what I have done so far and my test cycle is down to 13s.
1) Upgraded my processors. I moved from a single dual-core 2Ghz to two quad-core 2.5Ghz which shaved off around 5s.
2) Manually configured the build files, honestly I don't completely understand why it made such a difference but it shaved off almost 10s. http://netbeans.org/kb/docs/javaee/javaee-entapp-junit.html#Exercise_1d
Map<String, Object> properties = new HashMap<String, Object>();
// Use the MODULES property to specify the set of modules to be initialized,
// in this case a java.io.File
properties.put(EJBContainer.MODULES, new File("build/jar"));
3) Modified the persistence.xml to NOT create the database tables. I'll just have to turn it back on when making changes to the entity structure.
But the numbers are a little erratic and forgive me if I'm not going to take the time to do a proper statistical analysis. When I enable the "create" table in persistence and go back to the basic auto-config it runs in 16s. But before the processors arrived I had it down to 18s. So the numbers aren't quite adding up.
I was also extremely pleased to get a suggestion from Adam Bien. I asked him if he would be willing to write an article on this topic. He said it's covered specifically in this article and more detail can be found in his book and the other article:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With