How to make php and mysql use different cores - php

Kinda struggeling with mysql again...
Setup: vServer with 4 Cores, 1 gig RAM. Ubuntu 12.04 LTS, Serverpilot installed Apache (behind NGinx), PHP and MySQL.
When I run a script (runs kinda long, a few hours), it uses exactly 1 core - about 70% php, the rest mysql. Not stable of course, sometimes mysql isn't active at all, etc.
Is there a way to make mysql run on a different core? Connect to mysql via external IP does not solve it... ;-)
Thanks a lot!

I fear that your problem is that PHP is not a Threaded language. There are no good ways to do parallel processing in PHP (pthreads looks promising, but I was not able to build it successfully last I tried), which is probably what you really would need to speed up this script.

Check out numactl (http://linux.die.net/man/8/numactl) which you can include in your launcher for mysql. You could also use cset and taskset depending on what your distribution recommends, but that's how you can bind any process to a single core or package.

Related

Ubuntu - PHP server configuration, debugging performance issues

I have an ubuntu server that I've setup with PHP7 and nginx. It's running a Laravel application, and this runs on AWS. The MySQL DB is on RDS.
I've provisioned this server using Ansible. It's a pretty straightforward configuration. I have opcache enabled and ample php child processes. I also installed mysql-client to interface with RDS.
The issue: prior to provisioning this box, I was using a pre-provisioned box (from Laravel Forge). My new box seems to be MANY times slower than the pre-made box I previously used (5 to 8x slower!)
I've compared the settings between the two boxes and they are more or less the same, so I can't really figure out what would be causing this.
An example is: if I benchmark a particular piece of code on one of the more taxing endpoints, the actual sql queries are fast in both cases, but the new box seems to take an incredible amount of time populating the objects in Laravel, or maybe the application is getting queued up to wait for the database connection. It's hard to say. But the old box takes 50ms and the new one takes 1200ms.
My question is: what sorts of places should I be looking to find this issue, which seems to be in the server configuration? From what I can see, nginx and php seem properly configured. The issue happens when there's zero traffic, so I don't think it's a scaling problem. I'm wondering if there's some mysql-client configuration, or some mysql-php configuration that I could be overlooking. Any suggestions, or tools for debugging something like this would be appreciated.

Are Memcache and APC good together?

I have installed PHP5 - PHP5-MEMCACHE - PHP-APC.
Can they work like that together? Will the loading be fast with these modules ?
I tried to use them, I don't "see" particular differences, maybe the CPU is used less with these modules. My website doesn't have high traffic, but If i can save resources is better!
Thank you
APC keeps cache of PHP bytecode. Memcache keeps cache of your vars, that you set.
So answer is Yes, they can. They're made for different things.
They work together very well, you just need to use them properly :
Memcached is a distributed cache system. What that means in a nutshell is that if you have a cluster of servers all of them can access the same cache pool
APC is an opcache and local cache system. Meaning it optimizes the php scripts so when going through the compiler less operations are made and the code is executed way faster. Another use of APC is local cache, which means you can store values in the cache and access them from the machine running the code.
Yes, they can work together. Whether they will on a production system is another story...
Personally, I had to give up trying to get the following to work for any extended period of time:
Ubuntu 10.04
NGINX 0.7.65
PHP 5.3.2
php-apc
php5-memcache
It will run for awhile, but after stress testing php errors out. I can restart php-fastcgi via /etc/init.d/php-fastcgi and things will role along for some time more, but it always crashes again sooner than later.
I can run either/or without issue, but the two together won't cooperate for me. FYI I tried using binaries (apt-get packages), installing as PECL extensions, downloading source, but all roads lead me to the same sad fate. I also tried running the memache daemon local & remotely on my web host, but same outcome.
I'm working on mmo game based on JavaScript and PHP. We are using both of them. I can't tell you more, beacause I am only frontend developer, however I think if APC and memcache were bad we were not using it.

PHP, MySQL | Windows vs Linux

Well the title does the explaination. Which one is faster PHP/MySQL on Linux or on Windows.
Question 1
I know that MySQL is slower on Windows, because i tried to run a C++ program on Windows to access MySQL, it took a year every time it had to open a connection. When i ported the exact copy into the linux enviornment it was lightning fast.
Im not sure why the difference is, Maybe cause when we talk about Linux every thing is million times faster, but it would be good to know why such a massive difference.
Question 2
I have set up PHP on IIS and mySQL on Windows ive just tested a very small application on this setup and it seems fine. What i really want to know is that is there any performance issues for PHP in Windows rather than Linux?
Edit Windows Vista Was the OS i tried on Originally, Havent Tested W7. Fedora 10 was the Linux :D
They should be the same speed eventually. If you do an unscientific, unfair test, you might show a difference.
Process startup speed might be different. In particular, process startup might be slower on Windows. This shouldn't matter too much in production unless you're using a model which creates new processes on a very frequent basis, which will be inefficient on either.
Run a performance test of your actual application, with a large number of requests, over a significant length of time, on production-grade hardware. It's the only way to tell.
Needless to say, I can safely say that almost nobody chooses Windows vs Linux based on performance. Usually it's what they are capable of managing in production and have hardware / software support for.
If you're going to install 1000 boxes in production, Windows server licencing might get expensive (depending on your deal with MS). If you are only going to install a few, it probably doesn't matter (supporting the servers will be much more expensive).
Things are slowly getting better on Windows, with IIS 7 and PHP as a FastCGI ; see http://php.iis.net/
But I have never heard anything good about PHP + IIS6... Never worked in this configuration myself, though ; so I can't speak of experience.
One thing to consider is that Windows still (things are slowly getting better too) seems to be considered as a second-class citizen, when it comes to PHP...
And it's harder to get exactly the version of PHP you want (on Linux, you just recompile, and that's definitly not hard at all) ; even more for PECL extensions, btw...
As a sidenote : you can run PHP on windows with Apache ;-)
PHP is just about equally fast on Linux and Windows, variations among different functions.
PHP on linux used to support more functions Windows did not like pcntl_fork and socket_create_pair. It seems that with the release of version 5.3 those now works on both (from the PHP documentation).
I dont know about any speed difference between Apache on Linux vs IIS, or Apache on Linux vs Apache on Windows.
1) This is probably due to your mysql server trying to do a reverse lookup, and/or your DNS for localhost on the windows machine being incorrect.
2) PHP is the same speed, overall, however, the interface to it (apache module, cgi etc) may not be as fast.
Not sure what the issue was unless you had many of concurrent connections and/or were not running on windows server. There should be no noticeable speed difference between the two. There was something else going on in your program.

start php, apache?

I've just started reading about php, it needs me to install php, apache and MySql to run any php script. can any one suggest me a simplest method to install php, apache and MySql so that i can sun those php script.
I've tried the zip files from php.net, Are those required to run the script offline for practicing the script? what do i do with them? i felt the things given on the same site a bit complex, and was unable to run the script. please help.
I'm assuming you're using Windows - get wamp - it has exactly what you need:
Apache
MySQL
PHP
Wamp comes with a nifty tray controller app which you can use to access the most common tasks, like restarting services, editing config, etc.
Equivalent to Artem's post, just a different organization which packages it differently. And my preference. It is called XAMPP.
If you are using Windows, you could install XAMPP to have the environment setup for you. You'll then need to learn how to bring up the server (basically executing the XAMPP control panel program), copy your PHP scripts into the correct directories (for XAMPP, it'd be C:/[xampp installation dir]/htdocs), access MySQL and creating the necessary MySQL databases (you could access the MySQL via the included PhpMyAdmin).
You can probably refer to a tutorial here (it's a YouTube video, BTW).
Don't have enough rep to comment but wanted to add something to Artem's recommendation of Wampserver. It's what I use on my windows machine, and one of the nicest things about it I find is the ability to have multiple versions of versions of apache, php and mysql installed alongside each other as plug-ins and then select which to have running at any time. It makes it easy for me to emulate the eventual hosting environment for any given project.

Performance differences running PHP under Windows/IIS 7 vs. Linux/Apache?

There is a PHP application right now on a Linux box running under Apache with MySQL. Since we are a windows shop, management wants to get rid of the Linux box and move everything over to windows. Is there a performance difference between the two platforms? Or, is there any significant difference at all, in terms of performance or management?
Microsoft had a team help out optimising PHP for Windows, which work is part of PHP 5.3. Some figures I've seen places the performance close to PHP + Apache on a unix system. Before 5.3 (Which means currently, since 5.3 isn't out yet), performance is bad on Windows. I think there are some patches and tricks you can pull to improve it, but it's going to cost you a bit of performance. That may or may not be a problem; People have a tendency to overestimate performance.
Note that there are other reasons to use unix than just performance. Code may not be portable and even though the core php runs fairly ok, you can well get into trouble with php-extensions and third party libraries. No matter how you look at it, Windows is a second-rate system for running php on.
If your application isn't huge or get hit a couple thousand times per second, there's no difference between the two.
LAMP == WAMP in php small projects. Just install something like XAMPP if you want your environment to be as close as possible to your existing one but in Windows.
Good luck with your project!
You should consider the MS WebPI (download at www.microsoft.com/web ) which would install the entire stack for you to run PHP in IIS7 environment.
the performance is comparable for most apps.
I've just done this for the same reason. Mgt wanted to get rid of the Linux box. I was able to completely move my php application and MySQL database. It took longer for me to configure PHP for IIS than it did for me to move the existing content over.
I have found though that the IIS server is a fair bit slower when it comes to loading pages and images. Where in Linux it appeared instantaneous, in IIS it takes a half second for the page to load and another second for images.

Categories