ES压测
机器配置: CPU:4核 内存:8G 两台集群机器 ,以下入ES都是单个操作,批量操作所有耗时会相对变短。
一、10万数据
1、50个线程(实时刷新,设置方法参考:
)
①创建索引后,默认1s更新
耗时 | 131437ms(2分钟多) |
丢索引情况 | 无丢失 |
CPU情况 | 100%左右 |
内存使用情况 | 30%左右 |
异常情况 | 无 |
②创建索引后实时更新
耗时 | 1647341ms(27分钟多) |
丢索引情况 | 无丢失 |
CPU情况 | CPU经常300%~380% |
内存使用情况 | 30%左右 |
异常情况 | 无 |
ES的实时刷新性能比默认的1s刷新性能下降10倍。
2、100个线程(似乎100个线程没有全都用上)
①创建索引后,默认1s更新
耗时 | 140639ms |
丢索引情况 | 无丢失 |
CPU情况 | 100%左右 |
内存使用情况 | 30%左右 |
异常情况 | 无 |
②创建索引后实时更新
耗时 | 847928ms |
丢索引情况 | 无丢失 |
CPU情况 | CPU使用不断增加,后期维持在380%(CPU用尽) |
内存使用情况 | 30%左右 |
异常情况 | 无 |
3、设置30s更新,索引创建后,隔30s刷新(设置方式参考:
)
50个线程
耗时 | 279409ms |
丢索引情况 | 无丢失 |
CPU情况 | 基本都是10%以下,偶尔60%左右 |
内存使用情况 | 30%左右 |
异常情况 | 无 |
二、100万数据
1、50个线程
①创建索引后,默认1s更新
耗时 | 2246360ms |
丢索引情况 | 无丢失 |
CPU情况 | 有段时间30%左右,大部分100%左右(波动至100%时,索引创建很快,有可能是网络不好导致请求没有到达ES) |
内存使用情况 | 30%左右 |
异常情况 | 无 |
②创建索引后实时更新 太耗时,没有压测完。
Java压测代码:
package test;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicLong;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.WriteRequest.RefreshPolicy;
import org.elasticsearch.client.Client;
import product.Product;
import com.alibaba.fastjson.JSON;
/**
*
* Description: ES实时刷新,压测性能耗损情况
*
* //设置实时刷新
.setRefreshPolicy(RefreshPolicy.IMMEDIATE)
* CreateTime: 2017年9月23日 下午2:20:14
*
*/
public class EsTest {
private static int count = 50;
private static ExecutorService cachedThreadPool = Executors.newFixedThreadPool(count);
public static void main(String[] args) {
try {
System.out.println("es client init start");
long start = System.currentTimeMillis();
Client client = ElasticsearchConfiguration.getClient();
System.out.println("es client init end:"+(System.currentTimeMillis()-start)+"ms");
System.out.println("====================test start");
start = System.currentTimeMillis();
AtomicLong productId=new AtomicLong();
CountDownLatch countDownLatch = new CountDownLatch(count);
for (int i = 0; i < count; i++) {
cachedThreadPool.execute(new Runnable() {
@Override
public void run() {
System.out.println(1);
addProduct(productId, client);
countDownLatch.countDown();
}
});
}
countDownLatch.await();
System.out.println("总耗时:" + (System.currentTimeMillis()-start) + "ms");
cachedThreadPool.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
private static void addProduct(AtomicLong productId,Client client) {
int i = 0;
Product product = null;
for (; i < 20000; i++) {
try {
product = new Product();
product.setProductID(productId.incrementAndGet());
product.setProductName(getProductName());
product.setProductBrief("商品简介:"+UUID.randomUUID());
product.setPlaceProvince("河北省");
product.setPlaceCity("固安");
product.setProducer("獐子岛");
//设置实时刷新
IndexResponse response = client.prepareIndex("wareic-bak","product",product.getProductID().toString()).setSource(JSON.toJSONString(product)).setRefreshPolicy(RefreshPolicy.IMMEDIATE)
.get();
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(i);
}
private static String getProductName(){
String[]productNameArray={"西红柿番茄","西葫芦","宜家清新简约马克杯","螃蟹","文件柜","海鲜","电热水壶"};
return productNameArray[new Random().nextInt(6)]+new Random().nextInt(100000000);
}
}
ElasticsearchConfiguration类
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Arrays;
import java.util.List;
public class ElasticsearchConfiguration {
private static TransportClient client;
private static String clusterName;
private static List<String> clusterNodes;
static {
clusterName = "shopmall-es";
clusterNodes = Arrays.asList("http://172.16.32.69:9300","http://172.16.32.48:9300");
}
private ElasticsearchConfiguration() {
}
public static Client getClient() throws UnknownHostException {
Settings settings = Settings.builder().put("cluster.name", clusterName).build();
client = new PreBuiltTransportClient(settings);
for (String node : clusterNodes) {
URI host = URI.create(node);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName(host.getHost()), host.getPort()));
}
return client;
}
public static void close() {
client.close();
}
}
Product类
package test;
public class Product {
/**
* 商品ID
*/
private Long productID;
/**
* 商品编码
*/
private String productCode;
/**
* 商品名称
*/
private String productName;
/**
* 商品简介
*/
private String productBrief;
/**
* 商品主图URL地址
*/
private String imgUrl;
/**
* 商品产地省
*/
private String placeProvince;
/**
* 商品产地市
*/
private String placeCity;
/**
* 生产厂家
*/
private String producer;
public Long getProductID() {
return productID;
}
public void setProductID(Long productID) {
this.productID = productID;
}
public String getProductCode() {
return productCode;
}
public void setProductCode(String productCode) {
this.productCode = productCode;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductBrief() {
return productBrief;
}
public void setProductBrief(String productBrief) {
this.productBrief = productBrief;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getPlaceProvince() {
return placeProvince;
}
public void setPlaceProvince(String placeProvince) {
this.placeProvince = placeProvince;
}
public String getPlaceCity() {
return placeCity;
}
public void setPlaceCity(String placeCity) {
this.placeCity = placeCity;
}
public String getProducer() {
return producer;
}
public void setProducer(String producer) {
this.producer = producer;
}
}