Reputation: 41
How can I detect which function uses the cpu most? I get around 20 reqs/s usually, but the cpu usage is around %50 which is terrible. I have no doubts about the server's performance as it is mine.
I need to find out the most cpu consuming function in my script but I don't know how to do it. I use custom script, I've written it all.
Upvotes: 0
Views: 113
Reputation: 14269
In my opinion you can get very good results with Tideways and XHGUI.
Create file /etc/yum.repos.d/mongo-org-3.4.repo
with the following content
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/amazon/2013.03/mongodb-org/3.4/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
Install MongoDB – sudo yum install mongodb-org
service mongod start
sudo yum install php-pear
pecl install mongodb
php.ini
and restart PHP-FPM extension=mongodb.so
Create file /etc/yum.repos.d/tideways.repo
with the following content
[tideways]
name = Tideways
baseurl = https://s3-eu-west-1.amazonaws.com/qafoo-profiler/rpm
Import the RSA key - rpm --import https://s3-eu-west-1.amazonaws.com/qafoo-profiler/packages/EEB5E8F4.gpg
sudo yum install tideways-php
Edit the config /etc/php-5.6.d/40-tideways.ini
and disable autoprepending
tideways.auto_prepend_library=0
tideways.auto_start=0
tideways.sample_rate=100
Restart PHP-FPM – service php-fpm restart
/var/www
and rename the folder from xhgui-master
to just xhgui
chmod 777 /var/www/xhgui/cache
/var/www/xhgui/webroot
Create indexes in MongoDB
$ mongo
> use xhprof
> db.results.ensureIndex( { 'meta.SERVER.REQUEST_TIME' : -1 } )
> db.results.ensureIndex( { 'profile.main().wt' : -1 } )
> db.results.ensureIndex( { 'profile.main().mu' : -1 } )
> db.results.ensureIndex( { 'profile.main().cpu' : -1 } )
> db.results.ensureIndex( { 'meta.url' : 1 } )
> db.results.ensureIndex( { 'meta.simple_url' : 1 } )
> exit
Navigate to /var/www/xhgui
and run the installer – php install.php
Setup an autoprepend
directive in php.ini
and restart PHP-FPM
auto_prepend_file = /var/www/xhgui/external/header.php
To limit the disk usage of MongoDB (e.g. to 5 days = 432000 seconds)
$ mongo
> use xhprof
> db.results.ensureIndex( { "meta.request_ts" : 1 }, { expireAfterSeconds : 432000 } )
Upvotes: 1