< prev index next >

jdk/test/javax/management/remote/mandatory/notif/ListenerScaleTest.java

Print this page
rev 17427 : imported patch 8182154


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6338874
  27  * @summary Check that notification dispatch is not linear in number of MBeans.
  28  * @author Eamonn McManus
  29  *
  30  * @library /lib/testlibrary
  31  *
  32  * @run build jdk.testlibrary.* ListenerScaleTest
  33  * @run main ListenerScaleTest
  34  */
  35 
  36 /*
  37  * The notification dispatch logic in the connector server used to be
  38  * linear in the number of listeners there were on any MBean.  For
  39  * example, if there were 1000 MBeans, each with one listener, then
  40  * every time a notification was sent it would be compared against
  41  * every one of the 1000 MBeans, even though its source ObjectName was
  42  * known and could not possibly match the name of 999 of the MBeans.
  43  * This test checks that we no longer have linear behaviour.  We do
  44  * this by registering just one MBean and measuring the time it takes
  45  * to send and receive a certain number of notifications from that
  46  * MBean.  Then we register many other MBeans, each with a listener,
  47  * and we make the same measurement as before.  The presence of the
  48  * extra MBeans with their listeners should not impact the dispatch
  49  * time significantly.  If it does, the test fails.
  50  *
  51  * As usual with timing-sensitive tests, we could potentially get
  52  * sporadic failures.  We fail if the ratio of the time with many


  54  * fix in place, it is usually less than 1, presumably because some
  55  * code was being interpreted during the first measurement but had
  56  * been compiled by the second.
  57  */
  58 
  59 import java.util.concurrent.Semaphore;
  60 import javax.management.MBeanServer;
  61 import javax.management.MBeanServerConnection;
  62 import javax.management.MBeanServerFactory;
  63 import javax.management.MalformedObjectNameException;
  64 import javax.management.Notification;
  65 import javax.management.NotificationBroadcasterSupport;
  66 import javax.management.NotificationListener;
  67 import javax.management.ObjectName;
  68 import javax.management.remote.JMXConnector;
  69 import javax.management.remote.JMXConnectorFactory;
  70 import javax.management.remote.JMXConnectorServer;
  71 import javax.management.remote.JMXConnectorServerFactory;
  72 import javax.management.remote.JMXServiceURL;
  73 
  74 import jdk.testlibrary.Platform;
  75 
  76 public class ListenerScaleTest {
  77     private static final int WARMUP_WITH_ONE_MBEAN = 1000;
  78     private static final int NOTIFS_TO_TIME = 100;
  79     private static final int EXTRA_MBEANS = 20000;
  80 
  81     private static final ObjectName testObjectName;
  82     static {
  83         try {
  84             testObjectName = new ObjectName("test:type=Sender,number=-1");
  85         } catch (MalformedObjectNameException e) {
  86             throw new RuntimeException(e);
  87         }
  88     }
  89 
  90     private static volatile int nnotifs;
  91     private static volatile long startTime;
  92     private static volatile long elapsed;
  93     private static final Semaphore sema = new Semaphore(0);
  94 




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 6338874
  27  * @summary Check that notification dispatch is not linear in number of MBeans.
  28  * @author Eamonn McManus
  29  *
  30  * @library /test/lib
  31  *
  32  * @run build jdk.test.lib.Platform ListenerScaleTest
  33  * @run main ListenerScaleTest
  34  */
  35 
  36 /*
  37  * The notification dispatch logic in the connector server used to be
  38  * linear in the number of listeners there were on any MBean.  For
  39  * example, if there were 1000 MBeans, each with one listener, then
  40  * every time a notification was sent it would be compared against
  41  * every one of the 1000 MBeans, even though its source ObjectName was
  42  * known and could not possibly match the name of 999 of the MBeans.
  43  * This test checks that we no longer have linear behaviour.  We do
  44  * this by registering just one MBean and measuring the time it takes
  45  * to send and receive a certain number of notifications from that
  46  * MBean.  Then we register many other MBeans, each with a listener,
  47  * and we make the same measurement as before.  The presence of the
  48  * extra MBeans with their listeners should not impact the dispatch
  49  * time significantly.  If it does, the test fails.
  50  *
  51  * As usual with timing-sensitive tests, we could potentially get
  52  * sporadic failures.  We fail if the ratio of the time with many


  54  * fix in place, it is usually less than 1, presumably because some
  55  * code was being interpreted during the first measurement but had
  56  * been compiled by the second.
  57  */
  58 
  59 import java.util.concurrent.Semaphore;
  60 import javax.management.MBeanServer;
  61 import javax.management.MBeanServerConnection;
  62 import javax.management.MBeanServerFactory;
  63 import javax.management.MalformedObjectNameException;
  64 import javax.management.Notification;
  65 import javax.management.NotificationBroadcasterSupport;
  66 import javax.management.NotificationListener;
  67 import javax.management.ObjectName;
  68 import javax.management.remote.JMXConnector;
  69 import javax.management.remote.JMXConnectorFactory;
  70 import javax.management.remote.JMXConnectorServer;
  71 import javax.management.remote.JMXConnectorServerFactory;
  72 import javax.management.remote.JMXServiceURL;
  73 
  74 import jdk.test.lib.Platform;
  75 
  76 public class ListenerScaleTest {
  77     private static final int WARMUP_WITH_ONE_MBEAN = 1000;
  78     private static final int NOTIFS_TO_TIME = 100;
  79     private static final int EXTRA_MBEANS = 20000;
  80 
  81     private static final ObjectName testObjectName;
  82     static {
  83         try {
  84             testObjectName = new ObjectName("test:type=Sender,number=-1");
  85         } catch (MalformedObjectNameException e) {
  86             throw new RuntimeException(e);
  87         }
  88     }
  89 
  90     private static volatile int nnotifs;
  91     private static volatile long startTime;
  92     private static volatile long elapsed;
  93     private static final Semaphore sema = new Semaphore(0);
  94 


< prev index next >