文档章节

使用HashedWheelTimer进行调度

go4it
 go4it
发布于 2016/10/09 09:40
字数 245
阅读 11
收藏 0

##实例

public class PerformanceMetricsTask implements TimerTask {

    // Values to use with TimeOutTaskCreator
    // Count performance metrics every second
    public static final long DELAY = 1;
    public static final TimeUnit UNIT = TimeUnit.SECONDS;

    private static final int BYTES_PER_KILO = 1024;
    private ByteCounterHandler byteCounter;
    private MessageCounterHandler msgCounter;
    private static Logger logger = LoggerFactory.getLogger(PerformanceMetricsTask.class);

    public PerformanceMetricsTask(ByteCounterHandler byteCounter, MessageCounterHandler msgCounter) {
        this.msgCounter = msgCounter;
        this.byteCounter = byteCounter;
    }

    @Override
    public void run(Timeout timeout) throws Exception {

        if (logger.isInfoEnabled()) {

            // ****************************** Network Stats

            // Bytes read and written in kilobytes
            double bytesRead = (byteCounter != null) ? byteCounter.getReadBytesAndClear()
                    / (double) (BYTES_PER_KILO * DELAY) : 0;
            double bytesWritten = (byteCounter != null) ? byteCounter.getWrittenBytesAndClear()
                    / (double) (BYTES_PER_KILO * DELAY) : 0;

            // Message read and written in thousands
            double msgRead = (msgCounter != null) ? msgCounter.getReadMessagesAndClear()
                    / (double) (BYTES_PER_KILO * DELAY) : 0;
            double msgWritten = (msgCounter != null) ? msgCounter.getWrittenMessagesAndClear()
                    / (double) (BYTES_PER_KILO * DELAY) : 0;

            // ***************************** CPU / RAM Stats

            RamUsageInfo systemRam = PerformanceMetrics.instance().getSystemRamInfo();
            CpuUsageInfo cpuInfo = PerformanceMetrics.instance().getCpuUsageInfo();

            double cpuUsage = cpuInfo.totalPerc * 100;
            double ramUsage = (systemRam.ramUsed / (double) systemRam.ramMax) * 100;

            // Form the reqRespReport
            String reqRespReport = "\t(Key:AvgResp)";
            for (Integer key : ServerState.reqRespMetricsMap.keySet()) {
                ReqRespMetrics.Data rrMet = ServerState.reqRespMetricsMap.get(key).getAndResetInfo();

                double avgResp = (rrMet.totalNumReqResps == 0) ? 0 : rrMet.totalRespTime
                        / (double) rrMet.totalNumReqResps;
                reqRespReport += String.format("(" + OneMessage.Type.valueOf(key) + ":%.2f) ", avgResp);
            }
            reqRespReport += "\n";

            String networkReport = String.format("Performance Report\n"
                    + "\t(Read/Write): Messages(1000s): (%.2f/%.2f) KB: (%.2f/%.2f)\n", msgRead, msgWritten, bytesRead,
                    bytesWritten);
            String statusReport = String.format("\tNum Active Connections: %d Num Logger In Users: %d\n",
                    ServerState.numActiveConnections.longValue(), ServerState.numLoggedInUsers.longValue());
            String cpuMemReport = String.format("\tSystem CPU Usage (%%): %.2f System Ram Usage (%%): %.2f", cpuUsage,
                    ramUsage);
            logger.info(networkReport + reqRespReport + statusReport + cpuMemReport);
        }

        // Make this task recurring
        TimeOutTaskCreator.createTask(new PerformanceMetricsTask(byteCounter, msgCounter), DELAY, UNIT);
    }
}

##docs

© 著作权归作者所有

共有 人打赏支持
go4it
粉丝 51
博文 698
码字总数 498377
作品 0
深圳
Netty工具类HashedWheelTimer源码走读(一)

简单介绍. A Timer optimized for approximated I/O timeout scheduling. 关于Timer的介绍可以看看这篇文章, 写得不错 : http://novoland.github.io/%E5%B9%B6%E5%8F%91/2014/07/26/%E5%AE%9......

德胜
2015/08/07
0
0
Netty定时任务HashedWheelTimer

HashedWheelTimer 主要用来高效处理大量定时任务, 且任务对时间精度要求相对不高, 比如链接超时管理等场景, 缺点是, 内存占用相对较高 构造函数

休扬子
2016/10/15
88
0
Apache James出现You are creating too many HashedWheelTimer instances.提示

@悠树 你好,想跟你请教个问题: 你好,我使用了 james-server-container-spring-3.0-M2的邮箱服务器,在CentOS中安装部署,运行一段时间后提示: WARNING: You are creating too many Hashed...

cankongyun
2017/03/31
137
0
apache james 提示HashedWheelTimer创建过多

最近使用james邮件服务器搞了个邮件服务,仅使用IMAP协议收取邮件,每10秒检查5个账号是否有新邮件,机器内存2G,运行一段时间后提示: WARNING: You are creating too many HashedWheelTimer...

悠树
2014/06/16
395
0
netty的reconnect方式之一

使用timer timer HashedWheelTimerFactory ReconnectHandler docs TcpTransport

go4it
2016/10/08
21
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

sklearn中predict_proba用法(注意和predict的区别)

参考网址:https://blog.csdn.net/m0_37870649/article/details/79549142 # 返回预测标签 print(clf.predict(x_test)) # 返回预测属于某标签的概率 print(clf.predict_proba(x_test))...

小叮当_加V
3分钟前
0
0
docker swarm创建consul集群

version: '3.6'x-consul: &consul image: consul:latest volumes: - consul:/consulvolumes: consul:services: client: <<: *consul ports: - "8500:......

weidedong
4分钟前
0
0
Git客户端(TortoiseGit)基本使用详解

1、 环境安装 Git最新版下载地址:https://gitforwindows.org/ TortoiseGit,Git客户端,32/64位最新版及对应的语言包下载地址:https://tortoisegit.org/download/ 安装的方法,一直下一步就...

hblt-j
10分钟前
0
0
服务发现比较:Consul vs Zookeeper vs Etcd vs Eureka

这里就平时经常用到的服务发现的产品进行下特性的对比,首先看下结论: Feature Consul zookeeper etcd euerka 服务健康检查 服务状态,内存,硬盘等 (弱)长连接,keepalive 连接心跳 可配支持...

lemonLove
10分钟前
0
0
1、ElasticSearch的安装配置和使用

一、安装 按照个人习惯我习惯把自己的软件都安装到opt下 解压 tar -zxvf elasticsearch-6.3.2.tar.gz 重命名 mv elasticsearch-6.3.2.tar.gz esearch 移动 mv elasticsearch-6.3.2.tar.gz /o...

丑陋的皮囊
13分钟前
0
0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部