go-spacemesh icon indicating copy to clipboard operation
go-spacemesh copied to clipboard

logging: creating a logger.WithFields is not lazily initialized and will lead to significant allocations in the hot loop

Open dshulyak opened this issue 3 years ago • 3 comments

In particular, https://github.com/spacemeshos/go-spacemesh/blob/develop/tortoise/verifying.go#L203-L210 leads to 60Gb of memory allocated on the heap in an hour. The fix is simple, fields should be duplicated for every logline.

Adding this issue as a reminder to be wary of this pattern.

dshulyak avatar Jan 25 '22 03:01 dshulyak

@dshulyak i don't understand the root of this issue. i want to understand fully so i don't make mistake. can you give an example of fields should be duplicated for every logline, as opposed to

if _, exists := v.badBeaconBallots[ballot.id]; exists {
		logger.With().Debug("ballot is not good. ballot has a bad beacon")
		return bad
	}

thanks

countvonzero avatar Feb 02 '22 13:02 countvonzero

are you basically saying not to use logger = logger.WithFields()?

countvonzero avatar Feb 02 '22 13:02 countvonzero

So the problem came up with logging in determineGoodness. see pyroscope from current devnet. if log.WithFields is in the hot path it will cause a lot of allocations, even if log is not printed later.

are you basically saying not to use logger = logger.WithFields()?

i am not sure. it definitely should not be used in the hot path. but maybe there is some mistake in our wrapper, need to take a closer look

dshulyak avatar Feb 02 '22 13:02 dshulyak