Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
2c50b2c9
Commit
2c50b2c9
authored
5 years ago
by
gary rong
Committed by
Felix Lange
5 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd/geth: set up cache and metrics when starting node (#19911)
parent
9bad7fa7
master
v1.10.12
v1.10.12-modified
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
40 deletions
+46
-40
consolecmd.go
cmd/geth/consolecmd.go
+1
-0
main.go
cmd/geth/main.go
+45
-40
No files found.
cmd/geth/consolecmd.go
View file @
2c50b2c9
...
...
@@ -77,6 +77,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/JavaScript-Cons
// same time.
func
localConsole
(
ctx
*
cli
.
Context
)
error
{
// Create and start the node based on the CLI flags
prepare
(
ctx
)
node
:=
makeFullNode
(
ctx
)
startNode
(
ctx
,
node
)
defer
node
.
Close
()
...
...
This diff is collapsed.
Click to expand it.
cmd/geth/main.go
View file @
2c50b2c9
...
...
@@ -242,46 +242,6 @@ func init() {
if
err
:=
debug
.
Setup
(
ctx
,
logdir
);
err
!=
nil
{
return
err
}
// If we're a full node on mainnet without --cache specified, bump default cache allowance
if
ctx
.
GlobalString
(
utils
.
SyncModeFlag
.
Name
)
!=
"light"
&&
!
ctx
.
GlobalIsSet
(
utils
.
CacheFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
NetworkIdFlag
.
Name
)
{
// Make sure we're not on any supported preconfigured testnet either
if
!
ctx
.
GlobalIsSet
(
utils
.
TestnetFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
RinkebyFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
GoerliFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
DeveloperFlag
.
Name
)
{
// Nope, we're really on mainnet. Bump that cache up!
log
.
Info
(
"Bumping default cache on mainnet"
,
"provided"
,
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
),
"updated"
,
4096
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
4096
))
}
}
// If we're running a light client on any network, drop the cache to some meaningfully low amount
if
ctx
.
GlobalString
(
utils
.
SyncModeFlag
.
Name
)
==
"light"
&&
!
ctx
.
GlobalIsSet
(
utils
.
CacheFlag
.
Name
)
{
log
.
Info
(
"Dropping default light client cache"
,
"provided"
,
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
),
"updated"
,
128
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
128
))
}
// Cap the cache allowance and tune the garbage collector
var
mem
gosigar
.
Mem
// Workaround until OpenBSD support lands into gosigar
// Check https://github.com/elastic/gosigar#supported-platforms
if
runtime
.
GOOS
!=
"openbsd"
{
if
err
:=
mem
.
Get
();
err
==
nil
{
allowance
:=
int
(
mem
.
Total
/
1024
/
1024
/
3
)
if
cache
:=
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
);
cache
>
allowance
{
log
.
Warn
(
"Sanitizing cache to Go's GC limits"
,
"provided"
,
cache
,
"updated"
,
allowance
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
allowance
))
}
}
}
// Ensure Go's GC ignores the database cache for trigger percentage
cache
:=
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
)
gogc
:=
math
.
Max
(
20
,
math
.
Min
(
100
,
100
/
(
float64
(
cache
)
/
1024
)))
log
.
Debug
(
"Sanitizing Go's GC trigger"
,
"percent"
,
int
(
gogc
))
godebug
.
SetGCPercent
(
int
(
gogc
))
// Start metrics export if enabled
utils
.
SetupMetrics
(
ctx
)
// Start system runtime metrics collection
go
metrics
.
CollectProcessMetrics
(
3
*
time
.
Second
)
return
nil
}
...
...
@@ -299,6 +259,50 @@ func main() {
}
}
// prepare manipulates memory cache allowance and setups metric system.
// This function should be called before launching devp2p stack.
func
prepare
(
ctx
*
cli
.
Context
)
{
// If we're a full node on mainnet without --cache specified, bump default cache allowance
if
ctx
.
GlobalString
(
utils
.
SyncModeFlag
.
Name
)
!=
"light"
&&
!
ctx
.
GlobalIsSet
(
utils
.
CacheFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
NetworkIdFlag
.
Name
)
{
// Make sure we're not on any supported preconfigured testnet either
if
!
ctx
.
GlobalIsSet
(
utils
.
TestnetFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
RinkebyFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
GoerliFlag
.
Name
)
&&
!
ctx
.
GlobalIsSet
(
utils
.
DeveloperFlag
.
Name
)
{
// Nope, we're really on mainnet. Bump that cache up!
log
.
Info
(
"Bumping default cache on mainnet"
,
"provided"
,
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
),
"updated"
,
4096
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
4096
))
}
}
// If we're running a light client on any network, drop the cache to some meaningfully low amount
if
ctx
.
GlobalString
(
utils
.
SyncModeFlag
.
Name
)
==
"light"
&&
!
ctx
.
GlobalIsSet
(
utils
.
CacheFlag
.
Name
)
{
log
.
Info
(
"Dropping default light client cache"
,
"provided"
,
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
),
"updated"
,
128
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
128
))
}
// Cap the cache allowance and tune the garbage collector
var
mem
gosigar
.
Mem
// Workaround until OpenBSD support lands into gosigar
// Check https://github.com/elastic/gosigar#supported-platforms
if
runtime
.
GOOS
!=
"openbsd"
{
if
err
:=
mem
.
Get
();
err
==
nil
{
allowance
:=
int
(
mem
.
Total
/
1024
/
1024
/
3
)
if
cache
:=
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
);
cache
>
allowance
{
log
.
Warn
(
"Sanitizing cache to Go's GC limits"
,
"provided"
,
cache
,
"updated"
,
allowance
)
ctx
.
GlobalSet
(
utils
.
CacheFlag
.
Name
,
strconv
.
Itoa
(
allowance
))
}
}
}
// Ensure Go's GC ignores the database cache for trigger percentage
cache
:=
ctx
.
GlobalInt
(
utils
.
CacheFlag
.
Name
)
gogc
:=
math
.
Max
(
20
,
math
.
Min
(
100
,
100
/
(
float64
(
cache
)
/
1024
)))
log
.
Debug
(
"Sanitizing Go's GC trigger"
,
"percent"
,
int
(
gogc
))
godebug
.
SetGCPercent
(
int
(
gogc
))
// Start metrics export if enabled
utils
.
SetupMetrics
(
ctx
)
// Start system runtime metrics collection
go
metrics
.
CollectProcessMetrics
(
3
*
time
.
Second
)
}
// geth is the main entry point into the system if no special subcommand is ran.
// It creates a default node based on the command line arguments and runs it in
// blocking mode, waiting for it to be shut down.
...
...
@@ -306,6 +310,7 @@ func geth(ctx *cli.Context) error {
if
args
:=
ctx
.
Args
();
len
(
args
)
>
0
{
return
fmt
.
Errorf
(
"invalid command: %q"
,
args
[
0
])
}
prepare
(
ctx
)
node
:=
makeFullNode
(
ctx
)
defer
node
.
Close
()
startNode
(
ctx
,
node
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment