V
V
Vladimir San2011-11-17 21:09:37
PHP
Vladimir San, 2011-11-17 21:09:37

What are the possible load optimizations for the simplest script?

Hey!
There is an elementary script:

&lt;?php<br/>
if ($_GET['str'] != '')<br/>
{<br/>
echo strrev($_GET['str']);<br/>
}<br/>
else<br/>
{<br/>
echo 'error';<br/>
}<br/>
?&gt;<br/>

There are a large number of flash clients that knock on this script twice per second and receive a response using the URLLoader.
But the problem is that clients can and do send requests twice a second, but the answers reach much later, when there are already under two hundred clients. Everything happens on the local network.
The script runs on WAMP, machine configuration: core2duo 1.6Ghz, 1Gb RAM
What can be done (or read) to improve the situation?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
E
ertaquo, 2011-11-17
@KwI

It's more of a problem with the HTTP server. Try to implement the same on node.js or translate it to nginx+php-fpm if you are using Apache.

V
Vitaly Peretyatko, 2011-11-18
@viperet

If you really need to implement such strange functionality on the server, then you raise nginx + a simple fastcgi script written in C / C ++. Your task (string reversal) is implemented elementarily, it will work like a rocket.

E
edogs, 2011-11-17
@edogs

Firstly, if the script is exactly like this, then you don’t need a server script in FIG, what kind of disgrace is it to strain the server for this? :)
Secondly, put ob_start in the beginning, it can help a lot , though not in all cases, but there is, however, a striking difference.

A
avalak, 2011-11-17
@avalak

> The script works on WAMP
This I noticed. However, in this case it would be more interesting to use linux + nginx + php-fpm / node.js /
phpDeamon

  • linux.
    - You can customize the system (perhaps there is a way to do this in windows, but I don’t know) + I don’t know how nginx, php-fpm, node.js, phpDeamon are doing in this environment. The plan is this: create a disk in tmpfs/ramfs for cache. Make fine adjustments if necessary.
  • nginx.
    - Nginx has a caching function (we cache the result of the script in memory).
    - We set up routing through Nginx (we give the error as static, because it is not informative), the script is called only in a "combat" situation and when the result of such a request is not in the cache. We connect the script through the socket, the machine is one)
  • php5-fpm/node.js/phpDaemon
    - configure php to consume as little memory as possible (+apc).
    - since the script is simple, you can try the asynchronous version (you can squeeze a little more).

A
Anatoly, 2011-11-17
@taliban

Do you use exactly this script, or is there a read / write from a file? =)

E
Evengard, 2011-11-17
@Evengard

In general, indeed, a hellishly strange script, it is not clear why this functionality cannot be organized directly on the client.
In general, caching is necessary here IMHO. all sorts of memcacheds.
Well, of course, nginx + php-fpm, these people are also right.
But still. Consider implementing THIS on the client.

S
Sardar, 2011-11-18
@Sardar

It's hard to believe that the script in the example is real. If it's doing a lot of IO (files, pumping something off the network), then you need an asynchronous server, perhaps with a memcached cache. In the case of PHP, in my opinion, it is not solvable, the only thing is to raise as many cheap workers as possible. But on every request, the worker is locked on IO and is actually idle all the time.
Node.js has already been suggested, but I would recommend pyramid under gUnicorn:gevent, through nginx. An asynchronous server allows you to run as many green threads as you like, working cooperatively. If someone locks on IO, then he gives the processor to a neighbor. For each request, a new green thread.
I repeat, this is all only if your scripts block on IO or in some other way. If the task is CPU intensive, as in your example, then you just need to configure the server so that it fully uses all the resources of the machine (maybe there is one worker in the pool). Also find out what kind of network you have (maybe the “server” hangs on your home ADSL).

D
Dmitry Dedukhin, 2011-11-18
@Demetros

Use built-in perl/lua in nginx.
PS: what is the question - such is the answer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question