Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add APIs for tracking/debugging undesired object retention (aka "leaks") #7362

Merged
merged 1 commit into from
Apr 10, 2023

Conversation

FUDCo
Copy link
Contributor

@FUDCo FUDCo commented Apr 8, 2023

Closes #7318

Adds two and a half API features to aid debugging and testing for leaks of objects managed by LiveSlots:

  • The testHooks object returned by liveslots now contains a function getRetentionStats() that will return a data object containing the counts of the various non-singular objects that LiveSlots tracks internally. (LiveSlots keeps track of all these things in JavaScript Maps and Sets, so counting these objects is simply a matter of returning the sizes of these various collections. One consequence of this is that a getRetentionStats call will execute quickly regardless of how much stuff LiveSlots is holding onto.)

  • The testHooks object now also contains references to all these various Maps and Sets directly. Note that this is powerful and dangerous, but it's confined to the testHooks object which is only exposed during testing.

  • The data record that getRetentionStats produces is also returned as the result of every bringOutYourDead operation. From there it can be examined in tests, but, more signficantly, it will be output as part of the delivery status array that is written to the slog, so that a graph of object retention stats over time can be produced from a running chain or a long running performance test executing with a live swingset.

Collections passed in testHooks and counted by getRetentionStats:

Collection Type What
exportedRemotables B exported objects, to pin remotables; dropped on export drop
importedDevices B imported devices, to pin devices; grows monotonically
remotableRefCounts B objects referenced from off vat (from kernel or storage)
kernelRecognizableRemotables C exports recognizable by kernel
exportedVPIDs C promises exported; drop on resolve (vat is decider)
importedVPIDs C promises imported; drop on resolve (kernel is decider)
vrefRecognizers C vrefs used as keys in VirtualObjectAwareWeakMap/Set
definedDurableKinds D durable kinds that exist
kindInfoTable D info about kinds (durable + non-durable)
nextInstanceIDs D next id to allocate for kind once allocation has started
possiblyDeadSet E baseRefs to investigate for GC; cleared on BOYD
possiblyRetiredSet E vrefs to investigate for retirement; cleared on BOYD
slotToVal F live objects with vrefs
valToSlot E live objects with vrefs

Types:
A - Keyed by strings referring to virtual/durable store collections; cardinality is the total number of such stores
B - Keyed by direct references to explicitly in-memory objects; cardinality limited by RAM capacity
C - Keyed by strings referring to explicitly in-memory objects; cardinality limited by RAM capacity
D - Keyed by kindID strings; cardinality is number of defined knids (sometimes only durable kinds)
E - Transient collections, held weakly. Note that because they are weak collections they're not countable, so they lack corresponding counts in the retention stats
F - Keyed by vref strings referring to any kind of object currently addressable in memory

@FUDCo FUDCo added enhancement New feature or request SwingSet package: SwingSet performance Performance related issues labels Apr 8, 2023
@FUDCo FUDCo requested a review from warner April 8, 2023 01:19
@FUDCo FUDCo self-assigned this Apr 8, 2023
Copy link
Member

@warner warner left a comment

Choose a reason for hiding this comment

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

looks good, small changes recommended

packages/swingset-liveslots/src/collectionManager.js Outdated Show resolved Hide resolved
packages/swingset-liveslots/src/liveslots.js Outdated Show resolved Hide resolved
packages/swingset-liveslots/src/virtualReferences.js Outdated Show resolved Hide resolved
packages/swingset-liveslots/test/test-liveslots.js Outdated Show resolved Hide resolved
@FUDCo FUDCo force-pushed the 7318-leak-diagnostics branch from 27f1298 to 8678f93 Compare April 10, 2023 21:06
@FUDCo FUDCo added the automerge:rebase Automatically rebase updates, then merge label Apr 10, 2023
… "leaks")

Closes #7318

Adds two and a half API features for to aid debugging and testing for leaks of
objects managed by LiveSlots:

* The `testHooks` object returned by liveslots now contains a function
`getRetentionStats` that will return a data object containing the counts of the
various non-singular objects that LiveSlots tracks internally.  (LiveSlots keeps
track of all these things in JavaScript Maps and Sets, so counting these objects
is simply a matter of returning the sizes of these various collections.  One
consequence of this is that `getRetentionStats` call will execute quickly
regardless of how much stuff LiveSlots is holding onto.)

* The `testHooks` object now also contains references to all these various Maps
and Sets directly.  Note that this is powerful and dangerous, but it's confined
to the `testHooks` object which is only exposed during testing.

* The data record that `getRetentionStats` produces is also returned as the
result of every `bringOutYourDead` operation.  From there it can be examined in
tests, but, more signficantly, it will be output as part of the delivery status
array that is written to the slog, so that a graph of object retention stats
over time can be produced from a running chain or a long running performance
test executing with a live swingset.

Collections passed in `testHooks` and counted by `getRetentionStats`:

Collection | Type | What
------------|:-----|-----
exportedRemotables | B | exported objects, to pin remotables; dropped on export drop
importedDevices | B | imported devices, to pin devices; grows monotonically
remotableRefCounts | B | objects ref'd from off vat (kernel or storage)
kernelRecognizableRemotables | C | exports recognizable by kernel; tracks vrefs known to kernel, drop on export retire, retire when dead or kernel retire
exportedVPIDs | C | promises exported; drop on resolve (vat is decider)
importedVPIDs | C | promises imported; drop on resolve (kernel is decider)
vrefRecognizers | C | vrefs used as keys in VirtualObjectAwareWeakMap/Set
definedDurableKinds | D | durable kinds that exist
kindInfoTable | D | info about kinds (durable + non-durable)
nextInstanceIDs | D | next id to allocate for kind once allocation has started
possiblyDeadSet | E | baseRefs to investigate for GC; leared on BOYD
possiblyRetiredSet | E | vrefs to investigate for retirement; cleared on BOYD
slotToVal | F | live objects with vrefs
valToSlot | E | live objects with vrefs

Types:
A - Keyed by strings referring to virtual/durable store collections; cardinality is the total number of collections
B - Keyed by direct references to explicitly in-memory objects; cardinality limited by RAM capacity
C - Keyed by strings referring to explicitly in-memory objects;  cardinality limited by RAM capacity
D - Keyed by kindID strings; cardinality is number of defined knids (sometimes only durable kinds)
E - Transient collections; note that these have no counters since weak collections are not countable
F - Keyed by vref strings referring to any kind of object currently addressable in memory
@FUDCo FUDCo force-pushed the 7318-leak-diagnostics branch from 8678f93 to 0a7221b Compare April 10, 2023 22:07
@mergify mergify bot merged commit fb41c31 into master Apr 10, 2023
@mergify mergify bot deleted the 7318-leak-diagnostics branch April 10, 2023 23:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge:rebase Automatically rebase updates, then merge enhancement New feature or request performance Performance related issues SwingSet package: SwingSet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

write tool to track Representative leaks in a unit/benchmark test style
2 participants