点燃性能:瘦客户端vs胖客户端

时间:2019-09-04 09:56:51

标签: java caching ignite

我正在使用Apache Ignite v2.7.0。

最近,我从使用瘦客户端切换到了成熟的/胖客户端,因为它正确地支持了重新连接。我注意到的是,使用胖客户端时性能会更差。问题是:我可以在胖客户端的配置中调整一些参数以更接近瘦客户端的性能。

示例基准代码(只是一个凌乱的玩具代码,可以更好地显示差异):

@Configuration
public class ApacheIgniteConfiguration {

private String[] ips;

public ApacheIgniteConfiguration(@Value("${ignite.cache.address}") String[] ips) {
    this.ips = ips;
}

@Bean(name = "igniteClient")
public Ignite igniteClient() {
    if (this.ips != null && this.ips.length > 0) {
        TcpDiscoverySpi spi = new TcpDiscoverySpi();
        TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
        ipFinder.setAddresses(Arrays.stream(this.ips).collect(Collectors.toList()));
        spi.setIpFinder(ipFinder);

        IgniteConfiguration cfg = new IgniteConfiguration()
                .setClientMode(true)
                .setDiscoverySpi(spi)
                .setNetworkTimeout(60 * 1000)
                .setNetworkSendRetryCount(3)
                .setNetworkSendRetryDelay(10 * 1000);

        return Ignition.start(cfg);
    } else {
        return null;
    }
}

public static void main(String[] args){
    String[] ips = new String[]{"localhost"};
    try(Ignite client = new ApacheIgniteConfiguration(ips).igniteClient()){
        IgniteCache<Integer,String> cache = client.getOrCreateCache("test");
        for (int run = 0; run < 4; run++) {
            Instant putStart = Instant.now();
            for (int i = 0; i < 1000; i++) {
                cache.put(i, Integer.toString(i));
            }
            Instant putEnd = Instant.now();
            Instant getStart = Instant.now();
            for (int i = 0; i < 1000; i++) {
                cache.get(i);
            }
            Instant getEnd = Instant.now();

            System.out.printf("Run: %d, put: %d ms, get: %d ms \r\n", run,putStart.until(putEnd, ChronoUnit.MILLIS), getStart.until(getEnd, ChronoUnit.MILLIS));
        }
    }
}

 /*  public static void main(String[] args){
    String[] ips = new String[]{"localhost:10800"};
    ClientConfiguration cfg = new ClientConfiguration().setAddresses(ips);


    try( IgniteClient client = Ignition.startClient(cfg)){
        ClientCache<Integer,String> cache = client.getOrCreateCache("test");
        for (int run = 0; run < 4; run++) {
            Instant putStart = Instant.now();
            for (int i = 0; i < 1000; i++) {
                cache.put(i, Integer.toString(i));
            }
            Instant putEnd = Instant.now();
            Instant getStart = Instant.now();
            for (int i = 0; i < 1000; i++) {
                cache.get(i);
            }
            Instant getEnd = Instant.now();

            System.out.printf("Run: %d, put: %d ms, get: %d ms \r\n", run,putStart.until(putEnd, ChronoUnit.MILLIS), getStart.until(getEnd, ChronoUnit.MILLIS));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}*/

}

因此,第一个主要基准测试了胖客户端,并评论了一个瘦客户端。 结果如下:

厚客户端:

  

运行:0,输入:632 ms,获取:496 ms

     

运行:1,放置:354毫秒,获取:329毫秒

     

运行:2,放置:327 ms,获取:297 ms

     

运行:3,放置:316 ms,获取:285 ms

瘦客户端:

  

运行:0,输入:281 ms,获取:198 ms

     

运行:1,放置:214毫秒,获取:142毫秒

     

运行:2,放置:159毫秒,获取:143毫秒

     

运行:3,放置:159毫秒,获取:173毫秒

显然,由于jvm / cache预热,第一次运行会出现偏差,但总体性能要差2倍。

0 个答案:

没有答案