meg768 / rpi-matrix

2 stars 2 forks source link

100% cpu used by node process when importing (node 8.16.0) #2

Open buggedcom opened 5 years ago

buggedcom commented 5 years ago

I'm using fastify to to create a REST server to control the operation of the board, however as you can see the node process stays at 100% even when simply invoking the base class without setting any pixels. Is this to be expected?

Screenshot 2019-06-07 at 08 33 54 Screenshot 2019-06-07 at 08 37 40 Screenshot 2019-06-07 at 08 37 46

buggedcom commented 5 years ago

And even when not creating a new instance of the class it still is at 100% cpu

Screenshot 2019-06-07 at 08 54 58

meg768 commented 5 years ago

I just created a small sample.


Matrix.configure({'led-rows':32, 'led-cols':32});

class Sample  {

    constructor() {
        this.matrix = new Matrix({mode:'pixel'});
        this.offset = 0;
    }

    render() {
        this.matrix.clear();
        this.matrix.setPixel(this.offset % this.matrix.width, Math.floor(this.offset / this.matrix.width), this.matrix.color('red'));
        this.matrix.render();

        this.offset = (this.offset + 1) % (this.matrix.width * this.matrix.height);
    }

    run() {
        setInterval(this.render.bind(this), 100);
    }
};

var sample = new Sample();
sample.run();

When I run this code, node consumes about 70% cpu. Even if I set the interval to 10000 it still consumes about 70% cpu. There is a lot going on in the background to keep the matrix updated even when not drawing to it. I am using Hzellers active board. If you are using the passive board it might actually take 100% cpu...

buggedcom commented 5 years ago

Hmm. Running the demo's of Hzellers, even the most complex ones only top out at around 65% cpu for the process. I realise there is some extra usage because it has node on top but it seems a little extreme.

buggedcom commented 5 years ago

I would love to try to help debug why, but I have no C knowledge.

meg768 commented 5 years ago

I agree. But right now, I don't have a good answer. Matrix.configure() only calls Hzellers Init() function and allocates some arrays matching the size of the matrix.

meg768 commented 5 years ago

I do see some redundancies in my C++ code. Don't think it is the problem, but I will remove it anyway. Lesser code the better...

meg768 commented 5 years ago

Have removed as much code as I could (version 1.0.72), but still at 70% cpu when running a small pixel through the matrix...