Search in sources :

Example 1 with ThreadBurstExecutorService

use of alma.acs.concurrent.ThreadBurstExecutorService in project ACS by ACS-Community.

the class PerformanceTest method runConcurrentCalls.

private void runConcurrentCalls(String[] daos) throws Exception {
    long start;
    long end;
    double average;
    ThreadBurstExecutorService service;
    ThreadFactory threadFactory = new ThreadFactory() {

        public Thread newThread(Runnable r) {
            return new Thread(r);
        }
    };
    for (int j = 0; j != concurrentCallsIterations.length; j++) {
        System.out.println(" Asking for " + concurrentCallsIterations[j] + " nodes on each call");
        average = 0;
        for (int iteration = 0; iteration != CONCURRENT_CALLS_ITERATIONS; iteration++) {
            service = new ThreadBurstExecutorService(threadFactory);
            for (int i = 0; i != NUMBER_OF_CONCURRENT_CALLS; i++) service.submit(new DALClientCallable(daos, concurrentCallsIterations[j]), 30, TimeUnit.SECONDS);
            start = System.currentTimeMillis();
            service.executeAllAndWait(30, TimeUnit.SECONDS);
            end = System.currentTimeMillis();
            average += (end - start);
        }
        System.out.println("  Concurrent calls: " + NUMBER_OF_CONCURRENT_CALLS + ". Different nodes: " + daos.length + ". Tries: " + CONCURRENT_CALLS_ITERATIONS + ". Average time: " + average / CONCURRENT_CALLS_ITERATIONS + " [ms]");
    }
    System.out.println("");
}
Also used : ThreadBurstExecutorService(alma.acs.concurrent.ThreadBurstExecutorService) ThreadFactory(java.util.concurrent.ThreadFactory)

Example 2 with ThreadBurstExecutorService

use of alma.acs.concurrent.ThreadBurstExecutorService in project ACS by ACS-Community.

the class NCSubscriberAdminReuseTest method runConcurrentSubscribersCreation.

private void runConcurrentSubscribersCreation(int numRealSubscribersDefinedTotal) throws Exception {
    m_logger.info("Setting up " + numRealSubscribersDefinedTotal + " concurrent subscriber creations...");
    final List<AcsEventSubscriber<IDLEntity>> subscribers = Collections.synchronizedList(new ArrayList<AcsEventSubscriber<IDLEntity>>());
    // Create all the tasks first
    ThreadBurstExecutorService executor = new ThreadBurstExecutorService(getContainerServices().getThreadFactory());
    for (int i = 0; i < numRealSubscribersDefinedTotal; i++) {
        Runnable r = new Runnable() {

            public void run() {
                try {
                    // create subscriber, and add it to the list
                    subscribers.add(getContainerServices().createNotificationChannelSubscriber(CHANNEL_NAME, IDLEntity.class));
                } catch (Exception e) {
                    m_logger.log(Level.WARNING, "Failed to create a subscriber.", e);
                }
            }
        };
        try {
            executor.submit(r, 100, TimeUnit.SECONDS);
        } catch (InterruptedException e1) {
            fail("Failed to submit the subscriber creator thread to the executor service");
        }
    }
    // and now run'em all at the same time! (concurrently)
    m_logger.info("Will run " + numRealSubscribersDefinedTotal + " concurrent subscriber creations...");
    try {
        boolean startOK = executor.executeAllAndWait(100, TimeUnit.SECONDS);
        assertTrue("Not all subscribers started within the alotted 100 seconds window.", startOK);
    } catch (InterruptedException e) {
        fail("Got InterruptedException while running all my threads");
    }
    // After all the show, we should have all requested subscribers in the local list
    assertEquals(numRealSubscribersDefinedTotal, subscribers.size());
    m_logger.info("Successfully created " + numRealSubscribersDefinedTotal + " subscribers semi-concurrently. Will now check their NC admin links...");
    // Check if these subscribers are distributed correctly over several admin objects,
    // allowing for some overbooking due to concurrent requests (see comment about concurrency in c'tor of NCSubscriber)
    final int allowedAdminOverbooking = 2;
    int numRealSubscribersFoundTotal = 0;
    int[] adminIDs = channel.get_all_consumeradmins();
    for (int i = 0; i < adminIDs.length; i++) {
        int adminID = adminIDs[i];
        String msgBase = "Subscriber admin #" + (i + 1) + " (of " + adminIDs.length + ") ";
        try {
            int subs = channel.get_consumeradmin(adminID).push_suppliers().length;
            // minus 1 for the 'management' subscriber
            int numRealSubscribersThisAdmin = subs - 1;
            m_logger.info(msgBase + "has " + numRealSubscribersThisAdmin + " proxy objects (subscribers) attached.");
            if (i < adminIDs.length - 1) {
                // This is not the last of the admin objects. It should be  filled to the brim with proxies.
                assertThat(msgBase + "should be full with " + NCSubscriber.PROXIES_PER_ADMIN + " proxies.", numRealSubscribersThisAdmin, greaterThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN));
                assertThat(msgBase + "has more proxies than allowed by 'allowedAdminOverbooking'=" + allowedAdminOverbooking + ", which may be OK.", numRealSubscribersThisAdmin, lessThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN + allowedAdminOverbooking));
            } else {
                // We should be at the last of the admin objects, which may be only partially filled
                assertThat(msgBase + "has more proxies than allowed by 'allowedAdminOverbooking'=" + allowedAdminOverbooking + ", which may be OK.", numRealSubscribersThisAdmin, lessThanOrEqualTo(NCSubscriber.PROXIES_PER_ADMIN + allowedAdminOverbooking));
                assertThat(msgBase + "should contain all remaining proxies.", numRealSubscribersThisAdmin, equalTo(numRealSubscribersDefinedTotal - numRealSubscribersFoundTotal));
            }
            numRealSubscribersFoundTotal += numRealSubscribersThisAdmin;
        } catch (AdminNotFound ex) {
            fail("Can't get information about consumer admin #" + (i + 1) + " (ID=" + adminID + "): " + ex.toString());
        }
    }
    destroyConsumers();
}
Also used : ThreadBurstExecutorService(alma.acs.concurrent.ThreadBurstExecutorService) AcsEventSubscriber(alma.acs.nc.AcsEventSubscriber) IDLEntity(org.omg.CORBA.portable.IDLEntity) AdminNotFound(org.omg.CosNotifyChannelAdmin.AdminNotFound)

Aggregations

ThreadBurstExecutorService (alma.acs.concurrent.ThreadBurstExecutorService)2 AcsEventSubscriber (alma.acs.nc.AcsEventSubscriber)1 ThreadFactory (java.util.concurrent.ThreadFactory)1 IDLEntity (org.omg.CORBA.portable.IDLEntity)1 AdminNotFound (org.omg.CosNotifyChannelAdmin.AdminNotFound)1