Skip to content
This repository has been archived by the owner on Aug 2, 2021. It is now read-only.

swarm/shed: add metrics to each shed db #1029

Closed
wants to merge 4 commits into from
Closed

Conversation

nonsense
Copy link
Contributor

Currently it is kind of difficult to measure Swarm's disk usage, due to the very different setups we use. It'd be nice if we have a consistent view of the disk usage at least from the point of view of the Swarm process.

@nonsense nonsense requested review from janos and acud November 29, 2018 11:38
swarm/shed/db.go Outdated
}

// NewDB constructs a new DB and validates the schema
// if it exists in database on the given path.
func NewDB(path string) (db *DB, err error) {
// prefix is used for metrics collection for the given DB.
func NewDB(path string, prefix string) (db *DB, err error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just rename prefix to metricsPrefix as it is more clear what is it for.

It is also ok to have metrics optional. Not to call db.Meter in NewBD, but to explicitly call it only in implementation when it is needed. In that case prefix argument is not needed in NewDB.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no harm calling it for every single LevelDB, as metrics are gathered only once every 10sec. and AFAIK LevelDB also collects them always.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank Anton, I have anther suggestion. Not from the performance point of view, but to make code a bit more simple by removing the lock.

// Meter configures the database metrics collectors
func (db *DB) Meter(prefix string) {
// Initialize all the metrics collector at the requested prefix
db.compTimeMeter = metrics.NewRegisteredMeter(prefix+"compact/time", nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't *Meter fields assignments be under a lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. Why would they be under a lock? Meter is called once, when you initialise the DB, why would you initialise the same DB under different threads?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Meter is exported, it can be called any number of times, this is why I suggested not to export it, in the commend bellow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, Meter should not be exported. It should not be called a number of times, but only once.

}
}
// Update all the requested meters
if db.compTimeMeter != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All *Meter fields checks should be under a lock.

I have a suggestion, not to export Meter method, just to initialize metrics in NewDB, making them "immutable" from "outside" and to remove the lock completely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the problem is that Meter is exported.

Copy link
Member

@janos janos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @nonsense.

@zelig
Copy link
Member

zelig commented Dec 12, 2018

merged upstream as ethereum/go-ethereum#18277

@zelig zelig closed this Dec 12, 2018
@nonsense nonsense deleted the swarm-shed-metrics branch January 8, 2019 08:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants