1

I currently have apache running with web2py on windows using mod_wsgi and python 2.7.10. What I've noticed is when I have concurrent connections, the response time per request increases. This increase may go from 20ms for 1 connection to 200ms for 5 concurrent connections. If I get up to 20 concurrent connections, I have a response time of 800ms - 1s for a request that is only 545 B.

Would adding a front end like nginx help resolve this or is there something that can be changed in the apache config?

My current apache config limits are:

Threadlimit 100
ThreadsPerChild 100
MaxRequestsPerChild 10000
AcceptFilter http none
AcceptFilter https none
KeepAlive On

The code that is being executed is:

Javascript:

$(function () {
    function refresh(){
        $.get('/database/domath_stuff',  {num:document.getElementById('mathstuff').innerHTML}, function (response) {
            document.getElementById('mathstuff').innerHTML = response
        })
    }       
    window.setInterval(refresh, 1000);
});

The python is:

def domath_stuff():
    number = int(request.vars.num)
    number = number + 1
    return number
steve
  • 13
  • 6
  • It might help if you explain the nature of the requests or even show some code. For example, if these are concurrent Ajax requests coming from a single browser, the problem might that the session file is locked, serializing all requests. – Anthony May 04 '16 at 06:39

3 Answers3

1

nginx is typically faster than Apache, but with a low request server it hardly matters. There's dozens of different reasons why this could be happening; this is an incredibly common thing referred to as bottlenecking. The simplest explanation is that your application consumes more resources and accepts more concurrent transactions than what your server is able to handle, but since your requests are so low you can count them on one hand, the obvious answer is: your application is slow.

Josh
  • 3,258
  • 2
  • 19
  • 31
  • The application doesn't do anything more than take a div's inner HTML (that is a number), pass via ajax to a python controller, increment by 1 and return. The time increase occurs from when the ajax call is made to when it is received in the python controller. Apache's CPU consumption hits 35% which has me thinking maybe web2py could be a bottleneck? – steve May 03 '16 at 19:30
  • That's possible. I'm not sure how web2py works but if you've got 5 requests per second and only 1 thread, then it's going to slow down. And, I'm pretty sure Python is single threaded ... – Josh May 03 '16 at 19:34
0

The nginx server, as suggested by others as being an improvement, wouldn't help at all if the issue is in your Python code. This is because the request is not handled in nginx but whatever separate Python web hosting mechanism you are using.

A problem may be occurring in the Python application due to incorrect locking of some resource in the application or framework, causing serialisation of request handling. CPU bound tasks can also cause issues due to the Python global interpreter lock.

You could well be exacerbating the problems due to a poor Apache MPM configuration. Your thread directive values are inconsistent. ThreadsPerChild at 1000 is wrong as is greater than Threadlimit. Using a high number of threads in Python applications is also a bad idea because of the Python GIL issues. One would tend to small number of threads and multiple processes.

Unfortunately you are using Windows, which is a very poor platform for running Python web applications. Your Apache cannot handle multiple processes.

Depending on what HTTP client you are using for testing, the use of KeepAlive could also be complicating things and resulting in serialisation of requests.

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • The ThreadsPerChild of 1000 was a typo. It is currently set at 100. I've also added in the python/javascript the app is currently using. Why would using KeepAlive result in serialisation of requests? – steve May 04 '16 at 13:11
0

Using Graham's feedback, I switched over to IIS and I am now getting 20 concurrent connections < 200ms response time which for my needs is alright. I followed the web2py documentation in setting up IIS, so it's configured "out of the box" for anyone with this same issue.

steve
  • 13
  • 6