Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bottle loading time for network server is extremely slow

So i am currently working on a basic little website to run for my network. However, i am running into some problems. When i run the server, on the computer that is running the server, i can access the pages extremely quickly. However, when i try to access the same page on a different computer on my network, it loads EXTREMELY slowly. Is it because im using the dev. server and not something like Paste or Apache? (also to note, when im looking at the server computer, the logs for the requests come in about 5-6 seconds after i have requested it on my browser on the other computer)

My code is below:

Page being accessed:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="content-type"
 content="text/html; charset=ISO-8859-1">
  <title>index</title>
  <link type="text/css"
 href="cssfiles/mainpagecss.css"
 rel="stylesheet">
</head>
<body>
<table
 style="width: 100%; text-align: left; margin-left: auto; margin-right: auto;"
 border="0" cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td>
      <h1><span class="headertext">
      <center>Network
Website</center>
      </span></h1>
      </td>
    </tr>
  </tbody>
</table>
%if name!='none':
    <p align="right">signed in as: {{name}}</p>
%else:
    pass
%end
<br>
<table style="text-align: left; width: 100%;" border="0" cellpadding="2"
 cellspacing="2">
  <tbody>
    <tr>
      <td>
      <table style="text-align: left; width: 100%;" border="0"
 cellpadding="2" cellspacing="2">
        <tbody>
          <tr>
            <td style="width: 15%; vertical-align: top;">
            <table style="text-align: left; width: 100%;" border="1"
 cellpadding="2" cellspacing="2">
              <tbody>
                <tr>
                  <td>Home<br>
                  <span class="important">Teamspeak Download</span><br>
                  <span class="important">Teamspeak Information</span></td>
                </tr>
              </tbody>
            </table>
            </td>
            <td style="vertical-align: top;">
            <table style="text-align: left; width: 100%;" border="1"
 cellpadding="2" cellspacing="2">
              <tbody>
                <tr>
                  <td>
                  <h1><span style="font-weight: bold;">Network Website</span></h1>
To find all of the needed information relating to the network's social
capabilities, please refer to the links in the side bar.</td>
                </tr>
              </tbody>
            </table>
            </td>
          </tr>
        </tbody>
      </table>
      </td>
    </tr>
  </tbody>
</table>
</body>
</html>

Css:

  .headertext { color: rgb(51, 51, 51);
    }

  .bodytext {  }

  .important { font-weight: bold;
    }

Server:

from Bottle import route,run,template,request,static_file



@route('/')
def home():
    return template('Templates/',name=request.environ.get('REMOTE_ADDR'))

run(host='Work-PC',port=9999,debug=True)
like image 373
IT Ninja Avatar asked May 06 '12 22:05

IT Ninja


1 Answers

I know that I am late to the party, but I encountered this same problem. The default bottle server (WSGIRef from wsgiref.simple_server) does a reverse DNS lookup for every GET, POST, etc., so it can use the connecting hostname instead of its IP address in the web-log. This can unnecessarily slow things down, even if you have a fast DNS responder. :(

With just a little hacking on bottle.py, you can overload the underlying method which does the rDNS, BaseHTTPRequestHandler.address_string(), like so:

bottle.py

 class WSGIRefServer(ServerAdapter):
     def run(self, handler): # pragma: no cover
         from wsgiref.simple_server import make_server, WSGIRequestHandler
+        self.fast = True
+        self.quiet = False
+        if self.fast and self.quiet:  # disable logging and rDNS
+            class FastAndQuietHandler(WSGIRequestHandler):
+                def address_string(self): return self.client_address[0]
+                def log_request(*args, **kw): pass
+            self.options['handler_class'] = FastAndQuietHandler
+        elif self.fast:  # disable Reverse DNS Lookups -> faster service
+            class FastHandler(WSGIRequestHandler):
+                def address_string(self): return self.client_address[0]
+            self.options['handler_class'] = FastHandler
-        if self.quiet:
+        elif self.quiet:  # disable action entries to web-log
             class QuietHandler(WSGIRequestHandler):
                 def log_request(*args, **kw): pass
             self.options['handler_class'] = QuietHandler
         srv = make_server(self.host, self.port, handler, **self.options)
         srv.serve_forever()

I don't like patching the source, but until upstream accepts this patch, this works well IF you are determined to use the default server.

Credit: See - https://stackoverflow.com/a/6761844/538418

HTH

like image 143
Trevor Avatar answered Oct 05 '22 13:10

Trevor