Skip to content

Commit

Permalink
Rev948, Disable websocket logging, Change max files opened limit on s…
Browse files Browse the repository at this point in the history
…tartup
  • Loading branch information
shortcutme committed Mar 6, 2016
1 parent dba42f5 commit 2a06cec
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):

def __init__(self, argv):
self.version = "0.3.6"
self.rev = 943
self.rev = 948
self.argv = argv
self.action = None
self.config_file = "zeronet.conf"
Expand Down Expand Up @@ -149,6 +149,8 @@ def createArguments(self):
self.parser.add_argument('--disable_sslcompression', help='Disable SSL compression to save memory',
type='bool', choices=[True, False], default=True)
self.parser.add_argument('--keep_ssl_cert', help='Disable new SSL cert generation on startup', action='store_true')
self.parser.add_argument('--max_files_opened', help='Change maximum opened files allowed by OS to this value on startup',
default=1024, type=int, metavar='limit')
self.parser.add_argument('--use_tempfiles', help='Use temporary files when downloading (experimental)',
type='bool', choices=[True, False], default=False)
self.parser.add_argument('--stream_downloads', help='Stream download directly to files (experimental)',
Expand Down
8 changes: 7 additions & 1 deletion src/Ui/UiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def __init__(self):
self.sites = SiteManager.site_manager.list()
self.log = logging.getLogger(__name__)

# After WebUI started
def afterStarted(self):
from util import Platform
Platform.setMaxfilesopened(config.max_files_opened)

# Handle WSGI request
def handleRequest(self, env, start_response):
path = env["PATH_INFO"]
Expand Down Expand Up @@ -120,6 +125,7 @@ def start(self):

self.server = WSGIServer((self.ip.replace("*", ""), self.port), handler, handler_class=UiWSGIHandler, log=self.log)
self.server.sockets = {}
self.afterStarted()
try:
self.server.serve_forever()
except Exception, err:
Expand Down Expand Up @@ -149,4 +155,4 @@ def stop(self):

self.server.socket.close()
self.server.stop()
time.sleep(1)
time.sleep(1)
3 changes: 2 additions & 1 deletion src/lib/geventwebsocket/logging.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import absolute_import

from logging import getLogger, StreamHandler, getLoggerClass, Formatter, DEBUG
from logging import getLogger, StreamHandler, getLoggerClass, Formatter, DEBUG, INFO


def create_logger(name, debug=False, format=None):
Expand All @@ -27,5 +27,6 @@ def emit(x, record):
del logger.handlers[:]
logger.__class__ = DebugLogger
logger.addHandler(handler)
logger.setLevel(INFO)

return logger
24 changes: 24 additions & 0 deletions src/util/Platform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import logging


def setMaxfilesopened(limit):
try:
if sys.platform == "win32":
import win32file
maxstdio = win32file._getmaxstdio()
if maxstdio < limit:
logging.debug("Current maxstdio: %s, changing to %s..." % (maxstdio, limit))
win32file._setmaxstdio(limit)
return True
else:
import resource
soft, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
if soft < limit:
logging.debug("Current RLIMIT_NOFILE: %s, changing to %s..." % (soft, limit))
resource.setrlimit(resource.RLIMIT_NOFILE, (soft, hard))
return True

except Exception, err:
logging.error("Failed to modify max files open limit: %s" % err)
return False

0 comments on commit 2a06cec

Please sign in to comment.