Is there a known issue using a ignite semaphore with many concurrent requests?

We tried to use the igite semaphore to control access to resources in a cluster. At low concurrency viz. < 10 threads the semaphore seems to work as documented. However when we have 100’s of threads it the semaphore.tryAcquire(1, 100, TimeUnit.MILLISECONDS); starts taking a lot more than 100 sec. The expectation is that it will fail in 100ms. Actually we have seen it take 15, 20 or even 30 sec.

The semaphore.tryAcquire(1, 100, TimeUnit.MILLISECONDS) does not work as expected or documented at high conucrrency even when enough permits are available.

The following code is simplified representation of the production code.

public class IgniteSemaphoreTest {

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>private static final int THREAD_POOL_SIZE = 100 ;
private static IgniteSemaphore semaphore = null ;
/**
* This method can be used instead of semaphore.tryIgnite
* This improves the performance drastically.
* @param permits
* @param timeout
* @param tu
* @return
*/
private static synchronized boolean tryAcquire(int permits, int timeout, TimeUnit tu) {
return semaphore.tryAcquire(permits, timeout, tu);
}
public static void main(String[] args) throws Exception {
// Preparing IgniteConfiguration using Java APIs
IgniteConfiguration cfg = new IgniteConfiguration();
// The node will be started as a client node.
cfg.setClientMode(true);
cfg.setPeerClassLoadingEnabled(true);
cfg.setDeploymentMode(DeploymentMode.SHARED);
// Classes of custom Java logic will be transferred over the wire from this app.
CacheConfiguration<String, SomeFancyClass> cacheConfig = new CacheConfiguration<String, SomeFancyClass>("processortest");
cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cfg.setCacheConfiguration(cacheConfig);
// Setting up an IP Finder to ensure the client can locate the servers.
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500"));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));
// Starting the node
Ignite ignite = Ignition.start(cfg);
semaphore = ignite.semaphore("mySema12", // Distributed semaphore name.
100, // Number of permits.
true, // Release acquired permits if node, that owned them, left topology.
true // Create if it doesn't exist.
);
ExecutorService ser = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
int JOB_COUNT = 1000 ;
long [] time_taken = new long[JOB_COUNT];
for (int i = 0; i < JOB_COUNT; i++) {
final int index= i ;
ser.submit(() -> {
boolean acquired = false;
try {
long tm1 = System.currentTimeMillis();
acquired = semaphore.tryAcquire(1, 100, TimeUnit.MILLISECONDS);
long tm2 = System.currentTimeMillis();
long diff = tm2 - tm1;
if (acquired) {
System.out.println("Acquired in " + diff);
} else {
System.out.println("Not acquired in " + diff);
}
Thread.sleep((int)(Math.random()*1000));
time_taken[index] = diff ;
} catch (Exception e) {
} finally {
if (acquired) {
semaphore.release();
}
}
});
}
ser.shutdown();
while (!ser.awaitTermination(1, TimeUnit.SECONDS)) {
// nothing to do
}
Arrays.sort(time_taken);
System.out.println("P95 time = "+ percentile(time_taken, 95));
System.out.println("semaphore released");
System.out.println(">> Compute task is executed, check for output on the server nodes.");
try {
Thread.sleep(60000);
} catch (Exception e) {
e.printStackTrace();
}
// Disconnect from the cluster.
ignite.close();
}
public static long percentile(long [] latencies, double percentile) {
int index = (int) Math.ceil(percentile / 100.0 * latencies.length);
return latencies[index];
}
</code>
<code>private static final int THREAD_POOL_SIZE = 100 ; private static IgniteSemaphore semaphore = null ; /** * This method can be used instead of semaphore.tryIgnite * This improves the performance drastically. * @param permits * @param timeout * @param tu * @return */ private static synchronized boolean tryAcquire(int permits, int timeout, TimeUnit tu) { return semaphore.tryAcquire(permits, timeout, tu); } public static void main(String[] args) throws Exception { // Preparing IgniteConfiguration using Java APIs IgniteConfiguration cfg = new IgniteConfiguration(); // The node will be started as a client node. cfg.setClientMode(true); cfg.setPeerClassLoadingEnabled(true); cfg.setDeploymentMode(DeploymentMode.SHARED); // Classes of custom Java logic will be transferred over the wire from this app. CacheConfiguration<String, SomeFancyClass> cacheConfig = new CacheConfiguration<String, SomeFancyClass>("processortest"); cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL); cfg.setCacheConfiguration(cacheConfig); // Setting up an IP Finder to ensure the client can locate the servers. TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder(); ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500")); cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder)); // Starting the node Ignite ignite = Ignition.start(cfg); semaphore = ignite.semaphore("mySema12", // Distributed semaphore name. 100, // Number of permits. true, // Release acquired permits if node, that owned them, left topology. true // Create if it doesn't exist. ); ExecutorService ser = Executors.newFixedThreadPool(THREAD_POOL_SIZE); int JOB_COUNT = 1000 ; long [] time_taken = new long[JOB_COUNT]; for (int i = 0; i < JOB_COUNT; i++) { final int index= i ; ser.submit(() -> { boolean acquired = false; try { long tm1 = System.currentTimeMillis(); acquired = semaphore.tryAcquire(1, 100, TimeUnit.MILLISECONDS); long tm2 = System.currentTimeMillis(); long diff = tm2 - tm1; if (acquired) { System.out.println("Acquired in " + diff); } else { System.out.println("Not acquired in " + diff); } Thread.sleep((int)(Math.random()*1000)); time_taken[index] = diff ; } catch (Exception e) { } finally { if (acquired) { semaphore.release(); } } }); } ser.shutdown(); while (!ser.awaitTermination(1, TimeUnit.SECONDS)) { // nothing to do } Arrays.sort(time_taken); System.out.println("P95 time = "+ percentile(time_taken, 95)); System.out.println("semaphore released"); System.out.println(">> Compute task is executed, check for output on the server nodes."); try { Thread.sleep(60000); } catch (Exception e) { e.printStackTrace(); } // Disconnect from the cluster. ignite.close(); } public static long percentile(long [] latencies, double percentile) { int index = (int) Math.ceil(percentile / 100.0 * latencies.length); return latencies[index]; } </code>
private static final int THREAD_POOL_SIZE = 100 ;

private static IgniteSemaphore semaphore = null ;

/**
 * This method can be used instead of semaphore.tryIgnite 
 * This improves the performance drastically. 
 * @param permits
 * @param timeout
 * @param tu
 * @return
 */
private static synchronized boolean tryAcquire(int permits, int timeout, TimeUnit tu) {
    return semaphore.tryAcquire(permits, timeout, tu);
}


public static void main(String[] args) throws Exception {
    // Preparing IgniteConfiguration using Java APIs
    IgniteConfiguration cfg = new IgniteConfiguration();

    // The node will be started as a client node.
    cfg.setClientMode(true);
    cfg.setPeerClassLoadingEnabled(true);
    cfg.setDeploymentMode(DeploymentMode.SHARED);
    // Classes of custom Java logic will be transferred over the wire from this app.
    CacheConfiguration<String, SomeFancyClass> cacheConfig = new CacheConfiguration<String, SomeFancyClass>("processortest");
    cacheConfig.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
    cfg.setCacheConfiguration(cacheConfig);
    // Setting up an IP Finder to ensure the client can locate the servers.
    TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
    ipFinder.setAddresses(Collections.singletonList("127.0.0.1:47500"));
    cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(ipFinder));

    // Starting the node
    Ignite ignite = Ignition.start(cfg);

    semaphore = ignite.semaphore("mySema12", // Distributed semaphore name.
        100, // Number of permits.
        true, // Release acquired permits if node, that owned them, left topology.
        true // Create if it doesn't exist.
    );

    ExecutorService ser = Executors.newFixedThreadPool(THREAD_POOL_SIZE);
    int JOB_COUNT = 1000 ;
    long [] time_taken = new long[JOB_COUNT];
    for (int i = 0; i < JOB_COUNT; i++) {
        final int index= i ;
        ser.submit(() -> {
            boolean acquired = false;
            try {
                long tm1 = System.currentTimeMillis();
                acquired = semaphore.tryAcquire(1, 100, TimeUnit.MILLISECONDS);                        
                long tm2 = System.currentTimeMillis();
                long diff = tm2 - tm1;
                if (acquired) {
                    System.out.println("Acquired in " + diff);
                } else {
                    System.out.println("Not acquired in " + diff);
                }
                Thread.sleep((int)(Math.random()*1000));
                time_taken[index] = diff ;
            } catch (Exception e) {

            } finally {
                if (acquired) {
                    semaphore.release();
                }
            }

        });

    }

    ser.shutdown();

    while (!ser.awaitTermination(1, TimeUnit.SECONDS)) {
        // nothing to do
    }

    Arrays.sort(time_taken);
    System.out.println("P95 time = "+ percentile(time_taken, 95));
    System.out.println("semaphore released");

    System.out.println(">> Compute task is executed, check for output on the server nodes.");
    try {
        Thread.sleep(60000);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // Disconnect from the cluster.
    ignite.close();
}

public static long percentile(long [] latencies, double percentile) {
    int index = (int) Math.ceil(percentile / 100.0 * latencies.length);
    return latencies[index];
}

}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật