Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

High CPU load #11

Open
samek opened this issue Dec 12, 2013 · 5 comments
Open

High CPU load #11

samek opened this issue Dec 12, 2013 · 5 comments

Comments

@samek
Copy link

samek commented Dec 12, 2013

While I can use storm-php for my bolts I have very high CPU load.
This is probably because of while(true) $line = trim($this->readLine()); ?

If this is the case should we implement usleep or something to ease off when no data is coming ?

@Lazyshot
Copy link
Owner

The high CPU load is probably from the read loop. We should probably switch over to using stream_select and stream_get_line in the readLine method.

If you'd like to make the adjustments and see if this solves your CPU issue, then just submit a pull request. That would be greatly appreciated.

public function readLine()
{
   $result = stream_select(array(STDIN), array(), array(), 2);

   if ($result > 0)
   {
      return trim(stream_get_line(STDIN, 65535, "\n"));
   }
   else return "";
}

It may also be advantageous to do some research into using react

@samek
Copy link
Author

samek commented Dec 12, 2013

I'll test it tomorrow at work, @home it doest work since there's a bug in php 5.3.10 - stream_get_line();
And thanks for quick answer.

@samek
Copy link
Author

samek commented Dec 13, 2013

Do you know how tuples are sent to an php bolt ? Is it like
tail -f file | php bolt.php ?

Since when I'm trying to debug the bolt behaviour with tail (and the DEBUG log generated form the bolt) I don't get the load with current code and the new one, but if I do:
cat file | php bolt.php then the load is there.

So It might be that bolt got "disconnected" from the stream of tuples and therefor the load ?

@Lazyshot
Copy link
Owner

That's essentially what it looks like. Just a flooded stream of json. Multilang Protocol for more information.

It sounds like we aren't checking for EOF anywhere in that loop. So we get an infinite loop at the end of the file. IIRC, cat throws an EOF, while tail -f does not. So you could see the differences there. Try adding an feof check in the loop somewhere to kill the php bolt.

@rijnhard
Copy link

Out of curiosity Is this still an issue?
And to clarify, would it require react within storm-php or externally?

I'm doing research for a realtime analytics platform, and we will most likely make a symfony2 bundle encompassing this, as such could easily fork the code, but don't wan't to do the work double.

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

No branches or pull requests

3 participants