iron-fish / ironfish

A novel cryptocurrency focused on privacy and accessibility.
https://ironfish.network
Mozilla Public License 2.0
962 stars 576 forks source link

Worker pool: use the transfer feature and shared buffers for message posting #5127

Closed andiflabs closed 2 weeks ago

andiflabs commented 2 weeks ago

Summary

This changes the way the worker pool and the workers communicate in the following way:

The BackgroundNoteDecryptor used by the wallet scanner has been updated to make use of SharedArrayBuffer to store the account keys.

This is a draft because it requires https://github.com/iron-fish/jubjub/pull/4 to be merged first.

Testing Plan

Documentation

N/A

Breaking Change

N/A

patnir commented 2 weeks ago

These are the results I got -

on staging

        Command being timed: "node --expose-gc --inspect=:0 --inspect-publish-uid=http --enable-source-maps bin/run wallet:rescan -d /Users/patni/.if0"
        User time (seconds): 1.43
        System time (seconds): 0.23
        Percent of CPU this job got: 23%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:07.25
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 158400
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 4
        Minor (reclaiming a frame) page faults: 10470
        Voluntary context switches: 2219
        Involuntary context switches: 23857
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 1
        Socket messages received: 10391
        Signals delivered: 0
        Page size (bytes): 16384
        Exit status: 0

On your branch:

        Command being timed: "node --expose-gc --inspect=:0 --inspect-publish-uid=http --enable-source-maps bin/run wallet:rescan -d /Users/patni/.if0"
        User time (seconds): 1.34
        System time (seconds): 0.23
        Percent of CPU this job got: 20%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:07.67
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 156864
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 4
        Minor (reclaiming a frame) page faults: 10380
        Voluntary context switches: 1939
        Involuntary context switches: 26888
        Swaps: 0
        File system inputs: 0
        File system outputs: 0
        Socket messages sent: 1
        Socket messages received: 10403
        Signals delivered: 9
        Page size (bytes): 16384
        Exit status: 0

I see a slight reduction. I am running my own devnet with around 10k blocks.

andiflabs commented 2 weeks ago

I see a slight reduction. I am running my own devnet with around 10k blocks.

Given that this took only 1 user second (7 seconds of wall clock time), I think that not all the 10k blocks got scanned, but a small fraction of them. You should see a higher reduction if you reset the createdAt of your accounts, or if e.g. you scan the whole mainnet.

Regardless, the reduction will not be huge, as there are many allocations performed in other places of our codebase. This PR mainly focuses on reducing the allocations involved in scans, but time does not offer any way to differentiate between the two. The bottom line is: as long as time shows some reduction during scans, it means that this PR is doing what it's supposed to do.