Re: [PHP] Re: PHP as Application Server

2012-09-27 Thread Maciej Liżewski
to Matijn Woudt: you are right there should be something like: public
void synchronized increment(), but that is not the point. Sure there
are disadvantages and other problems but what Alessando is saying is
"I would not use cure for cancer even if it existed because it can
introduce other problems like overpopulation". There are cases when
"application server" adds much overhead that is not needed and there
are cases when it simplifies your tasks a lot. So from his mail the
only problem I can see is memory leaks, and I am not talking about
leaks in application because they can be caught in tests and fixed,
but mostly leaks in poorly wriiten PHP core and modules. Other like
session hijacking are not real problems (other languages somehow
managed it to work) or not so big in face of some other advantages
(like restarting application after change).

Robert Williams points that the main problem is with PHP programmers
who tend to ignore many aspects of multithreaded programming and PHP
helps them in that by hiding all threading aspects. There are still
people who can understand that and take profit from this knowlege.

The memory is also not such problem. I did some quite large PHP
projects and whole source code event if it were loaded in memory use
only few megabytes (event 100mb is not a problem). And am talking
about holding parsed structures in memory not the source files.
Applications I am talking about are mostly targeted to maximize
throughput and they are the only ones on server. In such cases *any*
speed improvement is worth attention.


I am not forcing anybody to use application server approach, but
rather like Robert said - good to have choice and decide on my own if
I want to write simple scripts or stateful application. The only
problem is that I do not have that choice not considering changing
language... at least I do not have such choice for now :)


2012/9/26 Robert Williams :
> On 9/26/12 10:18, "Matijn Woudt"  wrote:
>
>
>>Writing scripts for an application server requires a much deeper
>>understanding of threads and computer internals,so as a result it
>>probably increases error rate.
>
> Well... yes and no. PHP's architecture pretty much keeps you from having
> to mess with thread management, but it does so by shifting the burden to a
> higher level, either process management of multiple PHP processes or
> thread management within the context of the HTTP server. If your
> application is sufficiently simple, that shift may be enough to keep you
> from having to worry about the problem. For most applications, however,
> it's still a concern. In some ways, this can make things worse, simply
> because PHP programmers tend to be oblivious of the potential problems,
> whereas the typical C# or Java programmer has at least some awareness of
> the various traps that await them.
>
> As an example, I see PHP code *all the time* that is wide open to
> concurrency issues with the database. Most code just assumes it's the only
> code doing updates, but unless the server is set up to serialize requests,
> that's an invalid assumption. Recently, more folks have started to address
> this by using database transactions, but this is often done in ignorance
> of what isolation level is being used and what the impact of that is upon
> the code - which can just make things worse. Even when there is that
> awareness, there are database concurrency issues with which transactions
> can't help. (Of course, people who are aware of isolation levels also tend
> to be aware of other concurrency issues.) The point is, if you have
> multiple things running in parallel, whether that be threads within your
> application or entirely separate physical servers running multiple copies
> of your application, you have to deal with concurrency issues. It's a
> necessary evil of parallel programming, and no mere technological solution
> (language, database, whatever), now or in the future, can fully overcome
> it. Well, maybe an AI engine somewhere in the chain, but that's about it,
> and that's not coming anytime soon.
>
> Incidentally, another advantage of PHP's share-nothing approach that
> hasn't been mentioned is relatively easy scalability. In a shared pool
> architecture, the easiest way to scale is typically vertically, that is,
> adding RAM, faster drives, etc. This is fine, but you can only scale
> vertically to a certain point, which you can usually hit pretty quickly.
> With PHP's share-nothing approach, you can still scale vertically, but you
> can almost as easily scale horizontally by adding more servers that each
> run merrily in their own worlds, with the primary added coordination logic
> being in the areas of communicating with the database and the data cache,
> something the application should be designed with, anyway. In contrast,
> the shared approach requires added logic, somewhere, to coordinate the
> sharing amongst the pools of all that data that the application takes for
> granted is always available 

Re: [PHP] Re: PHP as Application Server

2012-09-26 Thread Maciej Liżewski
Well.. many things changed during last 30 years. Cobol is not
mainstream, we have got OOP, Java, Python, Ruby, Google and other
great things :)

I am talking about stateful application server. There are plenty
examples in other programming languages: Java has Jetty, Tomcat, Ruby
On Rails, Python and Passenger WSGI.
All of them have one common thing: application persist in memory
between requests. Even for interpreted languages (such Ruby) - this
has advantage of loading sources only once, parse it only once and
initialize memory structures for those definitions only once. On the
opposite - PHP loads EVERY single resource on every request. This is
why it needs op-code cachers, accelerators etc.
Another advantage of using stateful application servers is that you
can simply keep gloabal state of your application (global variables,
static object properties) in memory. It simplifies many tasks which in
PHP require sessions, writing files with serialized data and
deserialize them on every request...

Just imagine such scenarios:
now PHP acts like this on every request:
 1. locate resources (source files in this case), parse and load them
(possibly with op-code cache)
 2. initialize global context ($_SERVER, $GLOBALS, $_POST, $_GET, etc)
 3. run code
 4. destroy all resource and free memory for next request

persistent application servers load resources only on startup (or when
needed) and keep them in memory until programatically freed or until
end of application (server shutdown). So every request looks like
this:
 1. initialize global context
 2. run already parsed code

is that makes whole thing clear?

Another nice example - simple counter. In PHP you have to:
1. read file with counter
2. increment value
3. write serialized value to file
...on every request.

in Java (for example) you just write class:
class Counter {
  static private counter = 0;

  public void increment() {
this.counter++;
  }
}

and because class definition persists in application server - static
member is maintained between requests and whole things works as
expected...

2012/9/26 Jim Giner :
> On 9/26/2012 5:58 AM, Maciej Liżewski wrote:
>>
>> Hi,
>>
>> Maybe this topic have been already on board, but I could not find nothing
>> in google, so my question to PHP maintaneers (and other users too) is:
>>
>> Why there is no possibility to run PHP in "application server" way among
>> other SAPI modules and other possibilities to run PHP? PHP would encounter
>> great performance boost and became more "enterprise" :) Just look at Ruby
>> which is slow as hell compared even with PHP.
>>
>> By "application server" I mean scenario when there is statefull
>> application
>> on server side not only by session mechanizms but all classes definitions
>> maintained in memory (no need to load class definition on every request),
>> static class members (and their changes) persistent, background threads,
>> etc. This way any op-code cachers won't be necessary...
>>
>> sounds great, huh? others have it already, so why doesn't PHP? are there
>> any cons? problems too hard to solve (one can be memory leaks, thread safe
>> coding, etc)? I mean it - I am realy curious why there is no such
>> possibility and is there any hope we could get it?
>>
>> TIA for any answers on this topic.
>>
> Thirty+ years as a professional application designer, developer and manager
> and I don't have a clue about what you are proposing.  I must have been in a
> different world.  :)
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] PHP as Application Server

2012-09-26 Thread Maciej Liżewski
Hi,

Maybe this topic have been already on board, but I could not find nothing
in google, so my question to PHP maintaneers (and other users too) is:

Why there is no possibility to run PHP in "application server" way among
other SAPI modules and other possibilities to run PHP? PHP would encounter
great performance boost and became more "enterprise" :) Just look at Ruby
which is slow as hell compared even with PHP.

By "application server" I mean scenario when there is statefull application
on server side not only by session mechanizms but all classes definitions
maintained in memory (no need to load class definition on every request),
static class members (and their changes) persistent, background threads,
etc. This way any op-code cachers won't be necessary...

sounds great, huh? others have it already, so why doesn't PHP? are there
any cons? problems too hard to solve (one can be memory leaks, thread safe
coding, etc)? I mean it - I am realy curious why there is no such
possibility and is there any hope we could get it?

TIA for any answers on this topic.