Solr和HttpClient高并发 对比

本文通过实际测试对比了使用HttpClient解析URL获取数据与通过SolrAPI进行查询的速度。在10000次高并发请求下,HttpClient耗时247674ms,而SolrAPI仅耗时46938ms,后者速度快约5倍。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

公司需求 做了相关测试 关于HttpClient解析url 获取数据 和通过Solr API方式来获取参数来做相关查询 速度做相关对比

对比

1)httpClient的相应方法

 /**
     * Get方式发起请求
     *
     * @param url
     *            get请求的URL
     * @return
     */
    public static String requestByGetMethod(String url) {
        // 创建默认的httpClient实例
        CloseableHttpClient httpClient = getHttpClient();
        if (url.startsWith("https")) {
            try {
                httpClient = createSSLInsecureClient();
            }
            catch (GeneralSecurityException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        try {
            // 用get方法发送http请求
            HttpGet get = new HttpGet(url);
            CloseableHttpResponse httpResponse = null;
            // 发送get请求
            httpResponse = httpClient.execute(get);
            if(httpResponse.getStatusLine().getStatusCode() != 200){
                return "wrong";
            }
            try {
                // response实体
                HttpEntity entity = httpResponse.getEntity();
                if (null != entity) {
                    return EntityUtils.toString(entity, "UTF-8");
//                    return entity;
                }
            }
            finally {
                httpResponse.close();
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        finally {
            try {
                closeHttpClient(httpClient);
            }
            catch (IOException e) {
                e.printStackTrace();
            }
        }
        return null;
    }


因为测试相对要小一下 高并发10000情况下 HttpClient访问是247674ms,而且会报出N多错误

版本 Solr6.5.0 单机  数据规模大概1800W条数据

 通过Solr API查询 结果是46938ms


HttpClient Solr

247674ms VS46938ms 结果很明显 大概5倍的差距

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值