Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
3251c29f
Unverified
提交
3251c29f
authored
9月 05, 2016
作者:
Jakub Sztandera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
metrics: add hit counter for ARC and bloom caches
License: MIT Signed-off-by:
Jakub Sztandera
<
kubuxu@protonmail.ch
>
上级
a2bb6e8e
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
28 行增加
和
7 行删除
+28
-7
arc_cache.go
blocks/blockstore/arc_cache.go
+13
-3
arc_cache_test.go
blocks/blockstore/arc_cache_test.go
+1
-1
bloom_cache.go
blocks/blockstore/bloom_cache.go
+9
-2
caching.go
blocks/blockstore/caching.go
+5
-1
没有找到文件。
blocks/blockstore/arc_cache.go
浏览文件 @
3251c29f
package
blockstore
import
(
"github.com/ipfs/go-ipfs/blocks"
key
"gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key"
"github.com/ipfs/go-ipfs/blocks"
"gx/ipfs/QmRg1gKTHzc3CZXSKzem8aR4E3TubFhbgXwfVuWnSK5CC5/go-metrics-interface"
lru
"gx/ipfs/QmVYxfoJQiZijTgPNHCHgHELvQpbsJNTg6Crmc3dQkj3yy/golang-lru"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
ds
"gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
...
...
@@ -12,15 +14,21 @@ import (
type
arccache
struct
{
arc
*
lru
.
ARCCache
blockstore
Blockstore
hits
metrics
.
Counter
total
metrics
.
Counter
}
func
arcCached
(
bs
Blockstore
,
lruSize
int
)
(
*
arccache
,
error
)
{
func
newARCCachedBS
(
bs
Blockstore
,
ctx
context
.
Context
,
lruSize
int
)
(
*
arccache
,
error
)
{
arc
,
err
:=
lru
.
NewARC
(
lruSize
)
if
err
!=
nil
{
return
nil
,
err
}
c
:=
&
arccache
{
arc
:
arc
,
blockstore
:
bs
}
c
.
hits
=
metrics
.
NewCtx
(
ctx
,
"arc.hits_total"
,
"Number of ARC cache hits"
)
.
Counter
()
c
.
total
=
metrics
.
NewCtx
(
ctx
,
"arc_total"
,
"Total number of ARC cache requests"
)
.
Counter
()
return
&
arccache
{
arc
:
arc
,
blockstore
:
bs
}
,
nil
return
c
,
nil
}
func
(
b
*
arccache
)
DeleteBlock
(
k
key
.
Key
)
error
{
...
...
@@ -42,6 +50,7 @@ func (b *arccache) DeleteBlock(k key.Key) error {
// if ok == false has is inconclusive
// if ok == true then has respons to question: is it contained
func
(
b
*
arccache
)
hasCached
(
k
key
.
Key
)
(
has
bool
,
ok
bool
)
{
b
.
total
.
Inc
()
if
k
==
""
{
// Return cache invalid so the call to blockstore happens
// in case of invalid key and correct error is created.
...
...
@@ -50,6 +59,7 @@ func (b *arccache) hasCached(k key.Key) (has bool, ok bool) {
h
,
ok
:=
b
.
arc
.
Get
(
k
)
if
ok
{
b
.
hits
.
Inc
()
return
h
.
(
bool
),
true
}
return
false
,
false
...
...
blocks/blockstore/arc_cache_test.go
浏览文件 @
3251c29f
...
...
@@ -140,7 +140,7 @@ func TestGetAndDeleteFalseShortCircuit(t *testing.T) {
}
func
TestArcCreationFailure
(
t
*
testing
.
T
)
{
if
arc
,
err
:=
arcCached
(
nil
,
-
1
);
arc
!=
nil
||
err
==
nil
{
if
arc
,
err
:=
newARCCachedBS
(
nil
,
context
.
TODO
()
,
-
1
);
arc
!=
nil
||
err
==
nil
{
t
.
Fatal
(
"expected error and no cache"
)
}
}
...
...
blocks/blockstore/bloom_cache.go
浏览文件 @
3251c29f
...
...
@@ -6,6 +6,7 @@ import (
"github.com/ipfs/go-ipfs/blocks"
key
"gx/ipfs/Qmce4Y4zg3sYr7xKM5UueS67vhNni6EeWgCRnb7MbLJMew/go-key"
"gx/ipfs/QmVWBQQAz4Cd2XgW9KgQoqXXrU8KJoCb9WCrhWRFVBKvFe/go-metrics-interface"
bloom
"gx/ipfs/QmWQ2SJisXwcCLsUXLwYCKSfyExXjFRW2WbBH5sqCUnwX5/bbloom"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
...
...
@@ -18,6 +19,10 @@ func bloomCached(bs Blockstore, ctx context.Context, bloomSize, hashCount int) (
return
nil
,
err
}
bc
:=
&
bloomcache
{
blockstore
:
bs
,
bloom
:
bl
}
bc
.
hits
=
metrics
.
NewCtx
(
ctx
,
"bloom.hits_total"
,
"Number of cache hits in bloom cache"
)
.
Counter
()
bc
.
total
=
metrics
.
NewCtx
(
ctx
,
"bloom_total"
,
"Total number of requests to bloom cache"
)
.
Counter
()
bc
.
Invalidate
()
go
bc
.
Rebuild
(
ctx
)
...
...
@@ -33,8 +38,8 @@ type bloomcache struct {
blockstore
Blockstore
// Statistics
hits
uint64
misses
uint64
hits
metrics
.
Counter
total
metrics
.
Counter
}
func
(
b
*
bloomcache
)
Invalidate
()
{
...
...
@@ -84,6 +89,7 @@ func (b *bloomcache) DeleteBlock(k key.Key) error {
// if ok == false has is inconclusive
// if ok == true then has respons to question: is it contained
func
(
b
*
bloomcache
)
hasCached
(
k
key
.
Key
)
(
has
bool
,
ok
bool
)
{
b
.
total
.
Inc
()
if
k
==
""
{
// Return cache invalid so call to blockstore
// in case of invalid key is forwarded deeper
...
...
@@ -92,6 +98,7 @@ func (b *bloomcache) hasCached(k key.Key) (has bool, ok bool) {
if
b
.
BloomActive
()
{
blr
:=
b
.
bloom
.
HasTS
([]
byte
(
k
))
if
blr
==
false
{
// not contained in bloom is only conclusive answer bloom gives
b
.
hits
.
Inc
()
return
false
,
true
}
}
...
...
blocks/blockstore/caching.go
浏览文件 @
3251c29f
...
...
@@ -3,6 +3,7 @@ package blockstore
import
(
"errors"
"gx/ipfs/QmVWBQQAz4Cd2XgW9KgQoqXXrU8KJoCb9WCrhWRFVBKvFe/go-metrics-interface"
context
"gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
)
...
...
@@ -33,11 +34,14 @@ func CachedBlockstore(bs GCBlockstore,
if
opts
.
HasBloomFilterSize
!=
0
&&
opts
.
HasBloomFilterHashes
==
0
{
return
nil
,
errors
.
New
(
"bloom filter hash count can't be 0 when there is size set"
)
}
ctx
=
metrics
.
CtxSubScope
(
ctx
,
"bs.cache"
)
if
opts
.
HasBloomFilterSize
!=
0
{
cbs
,
err
=
bloomCached
(
cbs
,
ctx
,
opts
.
HasBloomFilterSize
,
opts
.
HasBloomFilterHashes
)
}
if
opts
.
HasARCCacheSize
>
0
{
cbs
,
err
=
arcCached
(
cbs
,
opts
.
HasARCCacheSize
)
cbs
,
err
=
newARCCachedBS
(
cbs
,
ctx
,
opts
.
HasARCCacheSize
)
}
return
cbs
,
err
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论