Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
f4d81178
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
f4d81178
编写于
6月 01, 2017
作者:
P
Péter Szilágyi
提交者:
GitHub
6月 01, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14563 from karalabe/ethstats-reduce-traffic-2
ethstats: reduce ethstats traffic by trottling reports
上级
310d2e7e
a355b401
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
22 deletion
+51
-22
ethstats/ethstats.go
ethstats/ethstats.go
+51
-22
未找到文件。
ethstats/ethstats.go
浏览文件 @
f4d81178
...
...
@@ -31,6 +31,7 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types"
...
...
@@ -119,7 +120,7 @@ func (s *Service) Stop() error {
// loop keeps trying to connect to the netstats server, reporting chain events
// until termination.
func
(
s
*
Service
)
loop
()
{
// Subscribe t
s
o chain events to execute updates on
// Subscribe to chain events to execute updates on
var
emux
*
event
.
TypeMux
if
s
.
eth
!=
nil
{
emux
=
s
.
eth
.
EventMux
()
...
...
@@ -132,6 +133,46 @@ func (s *Service) loop() {
txSub
:=
emux
.
Subscribe
(
core
.
TxPreEvent
{})
defer
txSub
.
Unsubscribe
()
// Start a goroutine that exhausts the subsciptions to avoid events piling up
var
(
quitCh
=
make
(
chan
struct
{})
headCh
=
make
(
chan
*
types
.
Block
,
1
)
txCh
=
make
(
chan
struct
{},
1
)
)
go
func
()
{
var
lastTx
mclock
.
AbsTime
for
{
select
{
// Notify of chain head events, but drop if too frequent
case
head
,
ok
:=
<-
headSub
.
Chan
()
:
if
!
ok
{
// node stopped
close
(
quitCh
)
return
}
select
{
case
headCh
<-
head
.
Data
.
(
core
.
ChainHeadEvent
)
.
Block
:
default
:
}
// Notify of new transaction events, but drop if too frequent
case
_
,
ok
:=
<-
txSub
.
Chan
()
:
if
!
ok
{
// node stopped
close
(
quitCh
)
return
}
if
time
.
Duration
(
mclock
.
Now
()
-
lastTx
)
<
time
.
Second
{
continue
}
lastTx
=
mclock
.
Now
()
select
{
case
txCh
<-
struct
{}{}
:
default
:
}
}
}
}()
// Loop reporting until termination
for
{
// Resolve the URL, defaulting to TLS, but falling back to none too
...
...
@@ -151,7 +192,7 @@ func (s *Service) loop() {
if
conf
,
err
=
websocket
.
NewConfig
(
url
,
"http://localhost/"
);
err
!=
nil
{
continue
}
conf
.
Dialer
=
&
net
.
Dialer
{
Timeout
:
3
*
time
.
Second
}
conf
.
Dialer
=
&
net
.
Dialer
{
Timeout
:
5
*
time
.
Second
}
if
conn
,
err
=
websocket
.
DialConfig
(
conf
);
err
==
nil
{
break
}
...
...
@@ -181,6 +222,10 @@ func (s *Service) loop() {
for
err
==
nil
{
select
{
case
<-
quitCh
:
conn
.
Close
()
return
case
<-
fullReport
.
C
:
if
err
=
s
.
report
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Full stats report failed"
,
"err"
,
err
)
...
...
@@ -189,30 +234,14 @@ func (s *Service) loop() {
if
err
=
s
.
reportHistory
(
conn
,
list
);
err
!=
nil
{
log
.
Warn
(
"Requested history report failed"
,
"err"
,
err
)
}
case
head
,
ok
:=
<-
headSub
.
Chan
()
:
if
!
ok
{
// node stopped
conn
.
Close
()
return
}
if
err
=
s
.
reportBlock
(
conn
,
head
.
Data
.
(
core
.
ChainHeadEvent
)
.
Block
);
err
!=
nil
{
case
head
:=
<-
headCh
:
if
err
=
s
.
reportBlock
(
conn
,
head
);
err
!=
nil
{
log
.
Warn
(
"Block stats report failed"
,
"err"
,
err
)
}
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Post-block transaction stats report failed"
,
"err"
,
err
)
}
case
_
,
ok
:=
<-
txSub
.
Chan
()
:
if
!
ok
{
// node stopped
conn
.
Close
()
return
}
// Exhaust events to avoid reporting too frequently
for
exhausted
:=
false
;
!
exhausted
;
{
select
{
case
<-
headSub
.
Chan
()
:
default
:
exhausted
=
true
}
}
case
<-
txCh
:
if
err
=
s
.
reportPending
(
conn
);
err
!=
nil
{
log
.
Warn
(
"Transaction stats report failed"
,
"err"
,
err
)
}
...
...
@@ -398,7 +427,7 @@ func (s *Service) reportLatency(conn *websocket.Conn) error {
select
{
case
<-
s
.
pongCh
:
// Pong delivered, report the latency
case
<-
time
.
After
(
3
*
time
.
Second
)
:
case
<-
time
.
After
(
5
*
time
.
Second
)
:
// Ping timeout, abort
return
errors
.
New
(
"ping timed out"
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录