Switching subdomains locally takes several seconds; what could it be?
I'm trying to test dynamic subdomains in the dev server. For this I added to the /etc/hosts
file:
127.0.0.1 www.myapp.dev
127.0.0.1 foo.myapp.dev
127.0.0.1 bar.myapp.dev
Then I start dev_appserver using --address开发者_如何学Python=www.myapp.dev
, and if I access any subdomain the app loads instantly. But if I access any other subdomain in sequence, it takes several seconds to load the same app/handler. Then if i leave the server idle for some time, accessing any subdomain is instantaneous again (and any different subdomain accessed in sequence takes, again, several seconds).
It could be something in my setup, or a dev server limitation, but I have no idea what it is. Do you know what it is and if there's a workaround?
For the record, I reproduced it with the simplest webapp app:
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
class Handler(webapp.RequestHandler):
def get(self):
self.response.out.write(self.request.host)
app = webapp.WSGIApplication([
('/', Handler),
])
def main():
util.run_wsgi_app(app)
if __name__ == '__main__':
main()
Er, sorry to answer my own question, but after installing dnsmask I figured the problem was Google Chrome being too smart.
To fix it, in Chrome 12 go to Preferences/Under the Hood, and uncheck "Predict network actions to improve page load performance". This was known as "DNS prefetching" in previous Chrome versions.
Now any subdomain loads instantly in dev server.
精彩评论