From PHP workers to Python threads -


Now I'm working on every machine in 50 PHP (CLI mode) workload (job) For example, an image Resizing the work they get the image (binary data) and the desired size in the workload. The worker works and returns the resized image. Then it is waiting for more jobs (loops in a smart way) I think I have the same executable, library and classes which are loaded 50 times. Am I right? Because it does not seem very effective.

Now I have a process that handles all the tasks and being able to use all available CPU cores only once being loaded efficient). I think a new thread will be started for each job and after the ending it will close the thread, if there are fewer than 50 threads in the work, more jobs will be accepted. If all 50 threads are busy, no additional jobs are accepted.

I am using a lot of libraries (for Memcach, Radis, MozillaFS, ...) to reach all the different components. And Python is the only language in addition to PHP, which supports all of them.

Can Python do what I want and will it be faster and more efficient in existing PHP solutions?

Most probably - yes but suppose you have to multithreading. Take a look at the multiprocessing module. It already includes the implementation of a pool, which you can use. And it basically solves the problem of GIL (Multithreading can only run 1 "standard python code" at any time - this is a very simple explanation).

It will still be a process per work process, but compared to starting all this in a different way, all the beginners-laborers loaded the libraries before entering the process-a copy-on - will be inherited in written manner. You will not start more than necessary, and you will not waste memory for the same Liberty / Class, if you have not actually separated the former pool state.

So yes - seeing only in this part, the dragon will ruin fewer resources and use the "good" employee-pool model. Is it really fast / low CPU-abuse, it is difficult to tell without testing, or at least viewing the code. Try it yourself.

Added: If you are worried about memory usage, then the dragon can also help as a "proper" garbage collector, while php is not a priority in GC (and not a good one) Also for good reason).


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -