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

Periodically recurring high CPU spikes (PHP 5.5/5.6) #83

Closed
lsrio opened this issue May 13, 2015 · 5 comments
Closed

Periodically recurring high CPU spikes (PHP 5.5/5.6) #83

lsrio opened this issue May 13, 2015 · 5 comments

Comments

@lsrio
Copy link

lsrio commented May 13, 2015

Rather than a bug in Phirehose, this issue is informative in nature: after upgrading to PHP 5.6.8, the consuming scripts caused high CPU spikes.
Debugging the source I found these originating here (Line 443 ironically):

https://github.com/fennb/phirehose/blob/master/lib/Phirehose.php#L443

$chunk_info=trim(fgets($this->conn)); //First line is hex digits giving us the length

It's caused by a bug in PHP:

https://bugs.php.net/bug.php?id=69402 / https://bugs.php.net/bug.php?id=69428

and fixed in PHP 5.6.9RC1:

https://github.com/php/php-src/blob/php-5.6.9RC1/NEWS

@fennb
Copy link
Owner

fennb commented May 14, 2015

Wow, this is incredibly helpful, thank you!

Do you mind posting this same information to the phirehose-users mailing list? (http://groups.google.com/group/phirehose-users)

@vishymuku
Copy link

Thanks @Lsrx for the info. I'm using aws ec2 t2.micro instance with php5.6.8. The moment i started connecting, I saw spikes of about 75-85%. Then over a period of 5-6hrs, it came down to 10%. Basically, t2.micro instances have a provisioned 10% cpu usage. Anymore than that, utilization credits have to be spent. So, the twitter stream connection exhausted the credits. Now also the instance is running at 10% utilization, negating all chances of earning back the credits for any burst of performance needed.

Question: What would be the immediate solution? roll-back to older version of php?

@vishymuku
Copy link

Thanks to a detailed response @fennb on #84, and a few links (listed at the end) I have been able to find a probable working solution.

I added this line to make the blocking true for the stream:

 stream_set_blocking($this->conn, TRUE);

Now CPU usage is down to <0.4%!

I tested it and I am able to get the tweets into database. But I don't know what the downside of blocking will be. As of now, I'll go ahead with this.

Here are the links which helped me:
an old bug(with funny comments at the end): https://bugs.php.net/bug.php?id=40566
from php manual: http://php.net/manual/en/function.stream-set-blocking.php

@lsrio
Copy link
Author

lsrio commented May 25, 2015

Ubunutu users out there, save on electricity costs: PPAs for PHP 5.6.9 are available now.
https://launchpad.net/~ondrej/+archive/ubuntu/php5-5.6/+index?batch=75&memo=75&start=75

@compwright
Copy link
Contributor

Noted in the readme. Thanks!

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

4 participants