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

Node 11 max CPU usage when connected to network #446

Closed
2 tasks done
Eligioo opened this issue Nov 8, 2018 · 3 comments
Closed
2 tasks done

Node 11 max CPU usage when connected to network #446

Eligioo opened this issue Nov 8, 2018 · 3 comments

Comments

@Eligioo
Copy link
Member

Eligioo commented Nov 8, 2018

New issue checklist

General information

  • Library version(s): 1.3.1
  • Browser version(s):
  • Devices/Simulators/Machine affected: Arch Linux, Node 11
  • Reproducible in the testnet? (Yes/No): Yes
  • Related issues:

Bug report

Expected behavior

Once you are trying to connect to the network, it will not use 100% of your CPU thread.

Actual behavior

Node 11.0.0: uses 100% of your CPU thread
Node 10.13.0 and 9 have a CPU thread usage of 1-2 %
I was running on version 11, then I switched to version 10.13.0.
Then I ran yarn && yarn build, to build the binaries for Node 10.
Ran the same script again and no issues.

Steps to reproduce

With NVM I switched to Node version 11.0.0
I run this piece of code:

const Nimiq = require('../../dist/node.js');
let $ = {}

const NIMIQ_NETWORK = "test"

module.exports = {
    async connect() {
        $.established = false;
        Nimiq.GenesisConfig[NIMIQ_NETWORK].call(this);

        console.log("Connecting to Nimiq Network: "+ NIMIQ_NETWORK);
        $.consensus = await Nimiq.Consensus.nano();
        
        $.blockchain = $.consensus.blockchain;
        $.mempool = $.consensus.mempool;
        $.network = $.consensus.network;
        
        $.consensus.on('established', () => this._onConsensusEstablished($));
        $.consensus.on('lost', () => {
            $.established = false;
            console.error('Consensus lost');
        });
        $.blockchain.on('head-changed', () => $.established ? this._onHeadChanged() : undefined)
        
        $.network.connect();
        },
    
    _onConsensusEstablished() {
        console.log('Consensus established.');
        $.established = true;
        console.log('height:', $.blockchain.height);
    },
    
    _onHeadChanged() {console.log("Head changed to:"+ $.blockchain.height)}
}

Once it calls $.network.connect();, your CPU usage goes up.
If you comment out this line, your CPU usage doesn't go up.

Crash log? Screenshots? Videos? Sample project?

When I run the above given code with Node 11.0.0.
On this image check PID: 13051
image

@jeffesquivels
Copy link
Member

Hi @Eligioo! Thanks for the issue report.

Doing a quick search, it seems this could be due to node.js' issue 23860 which should be fixed in node v11.1.0.

Can you try with this version and confirm if the issue is indeed fixed?

@Eligioo
Copy link
Member Author

Eligioo commented Nov 12, 2018

Hi @jeffesquivels! Yes I can confirm that in version 11.1.0 this issue doesn't happen anymore.
It was a total coincidence because one day after I installed 11.0.0, 11.1.0 came out.

Interesting to see that clearTimeout caused the issue.

@jeffesquivels
Copy link
Member

Hi @jeffesquivels! Yes I can confirm that in version 11.1.0 this issue doesn't happen anymore.

Nice! I'll close the issue then.

It was a total coincidence because one day after I installed 11.0.0, 11.1.0 came out.

Murphy's Law... it never fails 😄.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants