Why is this ajax call making web2py to freeze, even using session.forget?

58 views
Skip to first unread message

Lisandro

unread,
Dec 17, 2017, 8:41:50 AM12/17/17
to web2py-users
Hello everyone. I've read the docs [1] and also read several posts in this forum about this problem, however I can't figure out why it's still happening in my case. I was hoping you can help me.

In my application I have a simple page that makes an ajax async call to web2py in order to get some data. 
The controller/function that process the call takes a few seconds to complete (around 6-7 seconds).
During that time, if the user clics on a link in order to navigate to another page of the application, it doesn't respond. The whole application freezes until the ajax call completes.

In the documentation I've read about this, and this is the expected behaviour, because of the session file. So what I did is to put session.forget(response) at the top of the controller/function that process the ajax call. But this doesn't make any difference, the application still freezes until the ajax call is completed. I've also tried session.forget() and session._unlock(response) with no success.


This is the script that makes the ajax call:

<script type="text/javascript">
    $j
= jQuery.noConflict();
    $j
(document).ready(function() {
       $j
.ajax({
          type
: "GET",
          async
: true,
          url
: "{{=URL('default', '_dashboard')}}",
          success
: function(data) { $j(".dashboard").html(data) }
       
});
   
});
</script>



And this is the controller/function that process the call:

@auth.requires(auth.is_logged_in() and auth.user.plantel)
def _dashboard():
   
def get_info_dashboard():
       
from gluon.contrib.simplejsonrpc import ServerProxy
        webservice
= ServerProxy(CONFIG.url_webservice_central)
       
return webservice.get_info_dashboard({'sitio': CONFIG.cliente})

    session
.forget(response)
    info_dashboard
= None
   
try:
        r
= cache.redis('info-dashboard', lambda: get_info_dashboard(), time_expire=300)
       
if r.get('success'):
            info_dashboard
= r.get('info_dashboard')
   
except:
       
pass
   
return dict(info_dashboard=info_dashboard)



What could be the issue?

Thank you very much in advance.
Regards,

Anthony

unread,
Dec 17, 2017, 10:07:10 AM12/17/17
to web2py-users
How is web2py deployed?

Lisandro

unread,
Dec 17, 2017, 10:47:04 AM12/17/17
to web2py-users
Sorry, I forgot to mention.

I'm using nginx + uwsgi (cheaper busyness algorithm)
I use redis for cache and postgresql for database.

Anthony

unread,
Dec 17, 2017, 10:54:45 PM12/17/17
to web2py-users
How many uWSGI worker processes/threads? Is it possible you've got enough simultaneous long-running requests that all the available processes/threads are occupied at the same time?

Anthony

Lisandro

unread,
Dec 18, 2017, 7:23:26 AM12/18/17
to web2py-users
Thank you for your time Anthony, I think I've found the root cause of the issue.

Based on your last questions, I checked but there were enough available uwsgi workers. However I remembered my deploy involves a pooler for database connections (I use pgbouncer for postgres), and I have a pool size of only 1 connection per application. So I set a higher pool size, and then it started to work. I think that the bottleneck was there, in the database access, regardless of the session.forget(response). 

Sorry having bothered you with this.
Thank you very much, as always.

Best regards,
Lisandro.
Reply all
Reply to author
Forward
0 new messages