Skip to content

runtime: Unable to calculate memory usage of an object accurately #34561

@manishrjain

Description

@manishrjain

What version of Go are you using (go version)?

$ go version
go version go1.12.7 linux/amd64

Does this issue reproduce with the latest release?

Haven't checked with go1.13.1 yet.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/mrjn/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/mrjn/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build258461617=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Tried to calculate the memory usage on heap for a data structure.

https://github.com/dgraph-io/dgraph/blob/4203f983929671f45056beb92c282496ee7f79f6/posting/list.go#L71-L78

using various mechanisms before. But, the closest we have gotten is via this one:

https://github.com/creachadair/misctools/blob/4c938d6077e47ed42f6e7d6c8794b54e236dd23d/sizeof/size.go#L31

See PR: hypermodeinc/dgraph#4072 for more details.

What did you expect to see?

An accurate number of how many inuse bytes of space is being consumed by each such posting.List object.

What did you see instead?

Haven't been able to accurately gauge the memory usage of the struct. It is not as bad as we thought initially (https://twitter.com/manishrjain/status/1174743112444346369), sorry about crying wolf. But, still not fully accurate. We're off by around 40% based on a test data set.

// From cache log.
I0926 21:16:40.110860       1 lists.go:177] hit: 180578 miss: 32476354 keys-added: 4680373 keys-updated: 8 keys-evicted: 2227554
cost-added: 1736671951 cost-evicted: 736672031
sets-dropped: 10185369 sets-rejected: 3644105 gets-dropped: 8286464 gets-kept: 24236160 gets-total: 32656932 hit-ratio: 0.01

// From heap profile (in use memory).
// See posting.ReadPostingList using 1.38G.
// Cache shows usage as 1G (cost-added minus cost-evicted).
// Off by almost 40%.

  570.55MB 14.77% 14.77%  1381.37MB 35.76%  github.com/dgraph-io/dgraph/posting.ReadPostingList

What more could we be doing to accurate capture the inuse memory cost of a struct on heap?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions