文档章节

hystrix MaxConcurrentConnections reached 异常

go4it
 go4it
发布于 2017/03/28 11:14
字数 571
阅读 605
收藏 1

##报错1

2017-03-28 10:04:47.438 ERROR 1035 --- [InstanceMonitor] c.n.t.monitor.instance.InstanceMonitor   : Could not initiate connection to host, giving up: [{"timestamp":1490666687435,"status":503,"error":"Service Unavailable","message":"MaxConcurrentConnections reached: 5","path":"/hystrix.stream"}]

~/.m2/repository/com/netflix/hystrix/hystrix-metrics-event-stream/1.5.6/hystrix-metrics-event-stream-1.5.6-sources.jar!/com/netflix/hystrix/contrib/requests/stream/HystrixRequestEventsSseServlet.java

public class HystrixRequestEventsSseServlet extends HystrixSampleSseServlet {

    private static final long serialVersionUID = 6389353893099737870L;

    /* used to track number of connections and throttle */
    private static AtomicInteger concurrentConnections = new AtomicInteger(0);
    private static DynamicIntProperty maxConcurrentConnections =
            DynamicPropertyFactory.getInstance().getIntProperty("hystrix.config.stream.maxConcurrentConnections", 5);
    //......
}            

~/.m2/repository/com/netflix/hystrix/hystrix-metrics-event-stream/1.5.6/hystrix-metrics-event-stream-1.5.6-sources.jar!/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java

/**
     * - maintain an open connection with the client
     * - on initial connection send latest data of each requested event type
     * - subsequently send all changes for each requested event type
     *
     * @param request  incoming HTTP Request
     * @param response outgoing HTTP Response (as a streaming response)
     * @throws javax.servlet.ServletException
     * @throws java.io.IOException
     */
    private void handleRequest(HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
        final AtomicBoolean moreDataWillBeSent = new AtomicBoolean(true);
        Subscription sampleSubscription = null;

        /* ensure we aren't allowing more connections than we want */
        int numberConnections = incrementAndGetCurrentConcurrentConnections();
        try {
            int maxNumberConnectionsAllowed = getMaxNumberConcurrentConnectionsAllowed(); //may change at runtime, so look this up for each request
            if (numberConnections > maxNumberConnectionsAllowed) {
                response.sendError(503, "MaxConcurrentConnections reached: " + maxNumberConnectionsAllowed);
            } else {
                /* initialize response */
                response.setHeader("Content-Type", "text/event-stream;charset=UTF-8");
                response.setHeader("Cache-Control", "no-cache, no-store, max-age=0, must-revalidate");
                response.setHeader("Pragma", "no-cache");

                final PrintWriter writer = response.getWriter();

                //since the sample stream is based on Observable.interval, events will get published on an RxComputation thread
                //since writing to the servlet response is blocking, use the Rx IO thread for the write that occurs in the onNext
                sampleSubscription = sampleStream
                        .observeOn(Schedulers.io())
                        .subscribe(new Subscriber<String>() {
                            @Override
                            public void onCompleted() {
                                logger.error("HystrixSampleSseServlet: ({}) received unexpected OnCompleted from sample stream", getClass().getSimpleName());
                                moreDataWillBeSent.set(false);
                            }

                            @Override
                            public void onError(Throwable e) {
                                moreDataWillBeSent.set(false);
                            }

                            @Override
                            public void onNext(String sampleDataAsString) {
                                if (sampleDataAsString != null) {
                                    try {
                                        writer.print("data: " + sampleDataAsString + "\n\n");
                                        // explicitly check for client disconnect - PrintWriter does not throw exceptions
                                        if (writer.checkError()) {
                                            throw new IOException("io error");
                                        }
                                        writer.flush();
                                    } catch (IOException ioe) {
                                        moreDataWillBeSent.set(false);
                                    }
                                }
                            }
                        });

                while (moreDataWillBeSent.get() && !isDestroyed) {
                    try {
                        Thread.sleep(pausePollerThreadDelayInMs);
                    } catch (InterruptedException e) {
                        moreDataWillBeSent.set(false);
                    }
                }
            }
        } finally {
            decrementCurrentConcurrentConnections();
            if (sampleSubscription != null && !sampleSubscription.isUnsubscribed()) {
                sampleSubscription.unsubscribe();
            }
        }
    }

##报错2

10:45:53.194 INFO [http-nio-9002-exec-393] Caller+0	 at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:165)
 - 

Proxy opening connection to: http://localhost:9002/hystrix.stream


2017-03-28 10:45:53.209  WARN 1404 --- [o-9002-exec-393] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:9002/hystrix.stream : 503 : HTTP/1.1 503 
10:45:53.209 WARN [http-nio-9002-exec-393] Caller+0	 at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:212)
 - Failed opening connection to http://localhost:9002/hystrix.stream : 503 : HTTP/1.1 503 
2017-03-28 10:45:53.209  WARN 1404 --- [o-9002-exec-391] ashboardConfiguration$ProxyStreamServlet : Failed opening connection to http://localhost:9002/hystrix.stream : 503 : HTTP/1.1 503 
10:45:53.209 WARN [http-nio-9002-exec-391] Caller+0	 at org.springframework.cloud.netflix.hystrix.dashboard.HystrixDashboardConfiguration$ProxyStreamServlet.doGet(HystrixDashboardConfiguration.java:212)
 - Failed opening connection to http://localhost:9002/hystrix.stream : 503 : HTTP/1.1 503 

curl一下

➜  ~ curl -i http://localhost:9002/hystrix.stream
HTTP/1.1 503
X-Application-Context: recommend:9002
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Tue, 28 Mar 2017 02:48:23 GMT
Connection: close

{"timestamp":1490669303758,"status":503,"error":"Service Unavailable","message":"MaxConcurrentConnections reached: 20","path":"/hystrix.stream"}%

如果出现请求/hystrix.stream一直阻塞,或者报错Unable to connect to Command Metric Stream,表示你没有配置HystrixCommand。

解决方案

hystrix.config.stream.maxConcurrentConnections: 50

© 著作权归作者所有

go4it
粉丝 91
博文 1253
码字总数 1170728
作品 0
深圳
私信 提问
加载中

评论(0)

Hystrix概述(二)

一、hystrix在生产中的建议 1、保持timeout的默认值(1000ms),除非需要修改(其实通常会修改) 2、保持threadpool的的线程数为10个,除非需要更多 3、依赖标准的报警和监控系统来捕获问题 ...

李景枫
2016/07/19
2.1K
0
聊聊hystrix的queueSizeRejectionThreshold参数

序 本文主要研究一下hystrix的queueSizeRejectionThreshold参数 HystrixThreadPoolProperties hystrix-core-1.5.12-sources.jar!/com/netflix/hystrix/HystrixThreadPoolProperties.java 设计......

go4it
2018/07/04
243
0
教程:一起学习Hystrix--Hystrix处理异常机制(降级方法)

目录 降级 异常传递 惊喜 Fallback(降级) 我们可以通过增加一个 fallback (回退)方法在hystrix命令实现优雅降级,如果主命令失败,hystrix可以获取一个默认值或者值集合。我们可能想为更多的...

java_龙
2018/05/18
4.4K
0
教程:一起学习Hystrix--Hystrix常用场景--失败

目录 Hystrix本系列博文 快速失败 静默失败 声明 Hystrix本系列博文 以下为博主写Hystrix系列的文章列表 点击查看 Hystrix入门 点击查看 Hystrix命令执行 点击查看 Hystrix处理异常机制(降级...

java_龙
2018/05/23
863
0
Hystrix 源码解析 —— 请求执行(四)之失败回退逻辑

摘要: 原创出处 http://www.iocoder.cn/Hystrix/command-execute-fourth-fallback/ 「芋道源码」欢迎转载,保留摘要,谢谢! 本文主要基于 Hystrix 1.5.X 版本 1. 概述 2. handleFallback 3....

Java公众号_芋道源码_每日更新
2018/10/28
0
0

没有更多内容

加载失败,请刷新页面

加载更多

升级webpack4错误处理

1.升级到4.0之后未能正常使用 处理:npm i webpack webpack-cli webpack-dev-server webpack-merge -D 2. Error: Plugin could not be registered at 'html-webpack-plugin-before-html-proc......

李超明
15分钟前
50
0
几行Python代码,解决下载的视频教程中成百上千的文件夹/文件名称带广告词的困扰

直接上干货了。 原效果图: 我需要的效果, 你别跟我说:手工重命名,要是成百上千个文件你手工试试哦 执行情况: # -*- coding: utf-8 -*-"""Spyder EditorThis is a temporary scr...

郑加威
16分钟前
49
0
今天搞了下量子计算编程

operation QTest() : (Result, Result) { body { // 用于保存量子位状态的可变局部变量 mutable s1 = Zero; mutable s2 = Zero; // 分配两个量子位 using (qubits = Qubit[2]) { // 将第一个......

深圳市唤梦科技
21分钟前
46
0
如何在Postgres中查找所有表的行数

我正在寻找一种方法来查找Postgres中所有表的行数。 我知道我可以一次在一张桌子上做以下事情: SELECT count(*) FROM table_name; 但我想查看所有表的行数,然后按顺序进行排序,以了解我所...

技术盛宴
35分钟前
43
0
Mybatis自定义SQL更新JSON字段抛错

### Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property 'carouselPic'. It was either not specified and/or could not be found for the ......

huangkejie
36分钟前
50
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部