Im using the node package serverless-wsgi 1.4.9 to serve the routes of my serverless framework application
When I run by dev server serverless wsgi serve
I'm having problems with the requests taking a long time (10seconds - 1min) to return a response in chrome. To avoid hitting a database I'm sending GET request to a route that immediately returns 'hello world' 200.
So far the only predictable behaviour I can find is that making a request using jquery will always cause a long delay before returning. If I try to request the same URL in the browser tab (whilst the jquery request is still waiting) the tab also waits a long time for for the request to return.
However, once the jquery request returns, calling the URL in a browser tab then returns immediately. Refreshing the tab gives a response immediately.
Sometimes, if jquery request is pending, calling the URL in a browser tab WILL return immediately. When this happens, this seem to also make the jquery request return a response.
Jquery code below:
$( document ).ready(function() {
$.get("http://localhost:5000/test", function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
I've tried restarting the server, browsers and my machine, but the problem still persists.
I've tried multiple browsers (safari, chrome, firefox) and all have the same issue.
I've tried making a javascript request using axios instead of jquery but still the requests are returning slowly.
Does anyone have any idea how I might solve this or any additional debugging I can do?
Looks like this is mainly a problem with chrome and the way chrome uses preconnections
https://hackernoon.com/chrome-preconnect-breaks-singly-threaded-servers-95944be16400
The way to solve this is to set the WSGI server to allow threading. I have raised an issue with the team as its currently not possible to do this if you are using serverless-wsgi
.
As a work around, you can turn off the preconnection feature in chrome. Go to Settings > Advanced > Privacy and security and turn off Use a prediction service to load pages more quickly. This is now in Settings > Cookies and other site data > Preload pages for faster browsing and searching in more recent versions of Chrome.