good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
8e52c2e7
Commit
8e52c2e7
authored
Oct 19, 2016
by
Péter Szilágyi
Committed by
GitHub
Oct 19, 2016
Browse files
Options
Downloads
Plain Diff
Merge pull request #3161 from karalabe/trie-cache-counters
cmd/geth, trie: track and report trie cache misses
parents
c9471e77
2bb5ec1e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
cmd/geth/chaincmd.go
+14
-4
14 additions, 4 deletions
cmd/geth/chaincmd.go
trie/trie.go
+14
-0
14 additions, 0 deletions
trie/trie.go
with
28 additions
and
4 deletions
cmd/geth/chaincmd.go
+
14
−
4
View file @
8e52c2e7
...
@@ -31,6 +31,7 @@ import (
...
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util"
"github.com/syndtr/goleveldb/leveldb/util"
"gopkg.in/urfave/cli.v1"
"gopkg.in/urfave/cli.v1"
)
)
...
@@ -89,21 +90,30 @@ func importChain(ctx *cli.Context) error {
...
@@ -89,21 +90,30 @@ func importChain(ctx *cli.Context) error {
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
if
err
:=
utils
.
ImportChain
(
chain
,
ctx
.
Args
()
.
First
());
err
!=
nil
{
utils
.
Fatalf
(
"Import error: %v"
,
err
)
utils
.
Fatalf
(
"Import error: %v"
,
err
)
}
}
fmt
.
Printf
(
"Import done in %v
, compacting..
.
\n
"
,
time
.
Since
(
start
))
fmt
.
Printf
(
"Import done in %v.
\n
"
,
time
.
Since
(
start
))
// Compact the entire database to more accurately measure disk io and print the stats
if
db
,
ok
:=
chainDb
.
(
*
ethdb
.
LDBDatabase
);
ok
{
if
db
,
ok
:=
chainDb
.
(
*
ethdb
.
LDBDatabase
);
ok
{
// Output pre-compaction stats mostly to see the import trashing
stats
,
err
:=
db
.
LDB
()
.
GetProperty
(
"leveldb.stats"
)
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read database stats: %v"
,
err
)
}
fmt
.
Println
(
stats
)
// Compact the entire database to more accurately measure disk io and print the stats
start
=
time
.
Now
()
start
=
time
.
Now
()
if
err
:=
db
.
LDB
()
.
CompactRange
(
util
.
Range
{});
err
!=
nil
{
fmt
.
Println
(
"Compacting entire database..."
)
if
err
=
db
.
LDB
()
.
CompactRange
(
util
.
Range
{});
err
!=
nil
{
utils
.
Fatalf
(
"Compaction failed: %v"
,
err
)
utils
.
Fatalf
(
"Compaction failed: %v"
,
err
)
}
}
fmt
.
Printf
(
"Compaction done in %v.
\n
"
,
time
.
Since
(
start
))
fmt
.
Printf
(
"Compaction done in %v.
\n
"
,
time
.
Since
(
start
))
stats
,
err
:
=
db
.
LDB
()
.
GetProperty
(
"leveldb.stats"
)
stats
,
err
=
db
.
LDB
()
.
GetProperty
(
"leveldb.stats"
)
if
err
!=
nil
{
if
err
!=
nil
{
utils
.
Fatalf
(
"Failed to read database stats: %v"
,
err
)
utils
.
Fatalf
(
"Failed to read database stats: %v"
,
err
)
}
}
fmt
.
Println
(
stats
)
fmt
.
Println
(
stats
)
fmt
.
Println
(
"Trie cache misses:"
,
trie
.
CacheMisses
())
}
}
return
nil
return
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
trie/trie.go
+
14
−
0
View file @
8e52c2e7
...
@@ -20,6 +20,7 @@ package trie
...
@@ -20,6 +20,7 @@ package trie
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/crypto/sha3"
...
@@ -34,6 +35,17 @@ var (
...
@@ -34,6 +35,17 @@ var (
emptyState
common
.
Hash
emptyState
common
.
Hash
)
)
// cacheMisses maintains the number of times a trie node was loaded from disk.
// Always use atomic operations when accessing this global variable.
var
cacheMisses
uint64
// CacheMisses retrieves a global counter measuring the number of cache misses
// the trie did since process startup. This isn't useful for anything apart from
// trie debugging purposes.
func
CacheMisses
()
uint64
{
return
atomic
.
LoadUint64
(
&
cacheMisses
)
}
func
init
()
{
func
init
()
{
sha3
.
NewKeccak256
()
.
Sum
(
emptyState
[
:
0
])
sha3
.
NewKeccak256
()
.
Sum
(
emptyState
[
:
0
])
}
}
...
@@ -419,6 +431,8 @@ func (t *Trie) resolve(n node, prefix, suffix []byte) (node, error) {
...
@@ -419,6 +431,8 @@ func (t *Trie) resolve(n node, prefix, suffix []byte) (node, error) {
}
}
func
(
t
*
Trie
)
resolveHash
(
n
hashNode
,
prefix
,
suffix
[]
byte
)
(
node
,
error
)
{
func
(
t
*
Trie
)
resolveHash
(
n
hashNode
,
prefix
,
suffix
[]
byte
)
(
node
,
error
)
{
atomic
.
AddUint64
(
&
cacheMisses
,
1
)
enc
,
err
:=
t
.
db
.
Get
(
n
)
enc
,
err
:=
t
.
db
.
Get
(
n
)
if
err
!=
nil
||
enc
==
nil
{
if
err
!=
nil
||
enc
==
nil
{
return
nil
,
&
MissingNodeError
{
return
nil
,
&
MissingNodeError
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment