Skip to content

A lot of time is spent determining the size of the pending/queued transaction pool #16717

Closed
@veox

Description

@veox

EDIT: Original title: A lot of time is spent determining the length of txSortedMap

System information

Geth version: Geth/v1.8.7-stable-66432f38/linux-amd64/go1.10
OS & Version: Ubuntu 16.04.4 LTS (Xenial Xerus)

Background

I've tried to do txpool analysis, retaining as much of it as possible (e.g. having 32768 slots). My assumption was that this would mostly require copious amounts of memory, but it seemed to increase CPU load, too.

I've dropped the count down to 8192 and ran some profiling. (See link at the very bottom.)

Possible optimisation?..

In core/tx_pool.go, TxPool promoteExecutables() has a lot of nested loops that iterate over various lists of transactions.

Calls are made to txSortedMap's Len() (comes from core/tx_list.go); it seems that the structure does not have a specific field for this, so the determination is made on-the-fly.

In my tests, 5-10% of a "production" node's time is spent determining the length of these maps. This would seem to be true for most any txpool settings, unless severely restricting txpool.pricelimit.

(BTW, the default for that is 1 wei, which also contributes to the issue: the txpool is pretty much guaranteed to be immediately filled up by "default policy" peers, and remain in a constant state of churn from then on.)

Since this probably can't be avoided, perhaps it can be optimised for?..

Steps to reproduce the behaviour

Run geth something like:

/usr/bin/geth --metrics \
    --datadir /home/geth/.ethereum \
    --cache 3072 \ 
    --txpool.pricelimit 31337000 --txpool.accountslots 4 --txpool.globalslots 8192 --txpool.accountqueue 4 \
    --lightserv 50 --lightpeers 1000 --maxpeers 1025

In console:

debug.cpuProfile('/home/geth/fiddled.prof', 3600)

Generate SVG:

go tool pprof fiddled.prof
(pprof) svg > fiddled.svg

CPU profiling graph

https://veox.pw/dump/fiddled.svg

Note: this was intentionally timed to a window with little DB flushing.


Cc: @AlexeyAkhunov - not sure if you're mostly interested is sync optimisation, or runtime also.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions