On Aug 24, 10:36 am, pierreth <[email protected]> wrote:
> On 24 août, 01:20, mdipierro <[email protected]> wrote:
>
> > In Java a serverlet, as far as I understand, is a class which conforms
> > to some API that allows it to serve one http request. Each instance is
> > executed in its own thread.
>
> Yes, but one instance can be executed by multiple threads at the same
> time. It is one thread per request. EJB, Enterprise Java Beans, are
> running on their own threads.

it is the same in web2py

> >The Python equivalent of the serverlet API
> > is a WSGI application and web2py is based on WSGI, therefore the
> > parallelization mechanism is equivalent to Java serverlets.
>
> Is web2py running as a WSGI application when we do "python web2py.py"
> or is it only when used in a specific deployment with WSGI?

when you do "python web2py.py" you do not start the wsgi app. You
start the rocket web server which makes a number of threads. When a
new http request arrives it is assigned to a free thread (or a new
thread is created) and the wsgi is run in that thread to server that
request and only that request.

> > In web2py (the same in Django, Pylons, any any WSGI app) each http
> > request is executed in its own thread. Threads are recycled to server
> > non-concurrent requests and reuse database connections (pooling)
> > without need to close and reopen them. The web server can be
> > configured for a min number and a max number of threads.
>
> So, as a web2py developer, what do I have to do to avoid
> synchronization problems in my application. Where is the danger of
> having multiple threads for the web2py developers? What are the
> instances shared my multiple threads? What are the instances living in
> their own threads?

You do have to do anything because every concurrency issue is taken
care automatically. There are some DO NOTs:
- do not ever call os.chdir
- do not import third party modules that are not thread safe
- do not use thread.start_new_thread and threading.Thread.start()
- if you open a file that is not uniquely associate to this http/
request/client/session lock the file.

> > I think the GIL in this context is a false problem. In fact in
> > production you can use Apache and run as many processes as the number
> > of cores that you have. Each process will create as many threads as it
> > needs to server multiple requests. The GIL is a problems only if one
> > process runs multiple threads on multiple cores. It is possible there
> > are some caveats with many cores but I have not really played with
> > apache configurations and benchmarks.
>
> Yes but a web2py server is running with only one process and using
> more web2py processes for serving the same web2py app will lead to
> synchronization problems. With processors having more and more cores,
> having a web server that cannot use them is not very fun.

In production you should not use the rocket web server. Use Apache and
preform more than one process.

> It is an
> issue to be solved with Python 3.2 I think.

We are not moving to 3.2. Not at least until Google App Engine moves
to 3.x and all database drivers are supported. Than we'll open this
discussion.


> > Massimo
>
> Thank you for this precious information.

Reply via email to