more detailed stats, memory optimalizations, connection pinging and timeout, request timeout, validate content after signing, only recompile changed coffeescripts, remove unnecessary js logs

This commit is contained in:
HelloZeroNet 2015-03-06 02:31:51 +01:00
parent bd7e76628b
commit b35d21d643
13 changed files with 222 additions and 59 deletions

View file

@ -293,9 +293,8 @@ class UiRequest:
def actionStats(self):
import gc, sys
from greenlet import greenlet
greenlets = [obj for obj in gc.get_objects() if isinstance(obj, greenlet)]
self.sendHeader()
s = time.time()
main = sys.modules["src.main"]
yield """
<style>
@ -304,26 +303,76 @@ class UiRequest:
</style>
"""
# Memory
try:
import psutil
process = psutil.Process(os.getpid())
mem = process.get_memory_info()[0] / float(2 ** 20)
yield "Memory usage: %.2fMB | " % mem
yield "Threads: %s | " % len(process.threads())
yield "CPU: usr %.2fs sys %.2fs | " % process.cpu_times()
yield "Open files: %s | " % len(process.open_files())
yield "Sockets: %s" % len(process.connections())
yield "<br>"
except Exception, err:
pass
yield "Connections (%s):<br>" % len(main.file_server.connections)
yield "<table><tr> <th>id</th> <th>protocol</th> <th>ip</th> <th>zmqs</th> <th>ping</th> <th>buff</th> <th>idle</th> <th>delay</th> <th>sent</th> <th>received</th> </tr>"
yield "<table><tr> <th>id</th> <th>protocol</th> <th>type</th> <th>ip</th> <th>ping</th> <th>buff</th>"
yield "<th>idle</th> <th>open</th> <th>delay</th> <th>sent</th> <th>received</th> <th>last sent</th> <th>waiting</th> <th>version</th> <th>peerid</th> </tr>"
for connection in main.file_server.connections:
yield self.formatTableRow([
("%3d", connection.id),
("%s", connection.protocol),
("%s", connection.type),
("%s", connection.ip),
("%s", bool(connection.zmq_sock)),
("%6.3f", connection.last_ping_delay),
("%s", connection.incomplete_buff_recv),
("since", max(connection.last_send_time, connection.last_recv_time)),
("since", connection.start_time),
("%.3f", connection.last_sent_time-connection.last_send_time),
("%.0fkB", connection.bytes_sent/1024),
("%.0fkB", connection.bytes_recv/1024)
("%.0fkB", connection.bytes_recv/1024),
("%s", connection.last_cmd),
("%s", connection.waiting_requests.keys()),
("%s", connection.handshake.get("version")),
("%s", connection.handshake.get("peer_id")),
])
yield "</table>"
yield "Greenlets (%s):<br>" % len(greenlets)
for thread in greenlets:
yield " - %s<br>" % cgi.escape(repr(thread))
from greenlet import greenlet
objs = [obj for obj in gc.get_objects() if isinstance(obj, greenlet)]
yield "<br>Greenlets (%s):<br>" % len(objs)
for obj in objs:
yield " - %sbyte: %s<br>" % (sys.getsizeof(obj), cgi.escape(repr(obj)))
from Worker import Worker
objs = [obj for obj in gc.get_objects() if isinstance(obj, Worker)]
yield "<br>Workers (%s):<br>" % len(objs)
for obj in objs:
yield " - %sbyte: %s<br>" % (sys.getsizeof(obj), cgi.escape(repr(obj)))
from Connection import Connection
objs = [obj for obj in gc.get_objects() if isinstance(obj, Connection)]
yield "<br>Connections (%s):<br>" % len(objs)
for obj in objs:
yield " - %sbyte: %s<br>" % (sys.getsizeof(obj), cgi.escape(repr(obj)))
objs = [obj for obj in gc.get_objects() if isinstance(obj, self.server.log.__class__)]
yield "<br>Loggers (%s):<br>" % len(objs)
for obj in objs:
yield " - %sbyte: %s<br>" % (sys.getsizeof(obj), cgi.escape(repr(obj.name)))
objs = [obj for obj in gc.get_objects() if isinstance(obj, UiRequest)]
yield "<br>UiRequest (%s):<br>" % len(objs)
for obj in objs:
yield " - %sbyte: %s<br>" % (sys.getsizeof(obj), cgi.escape(repr(obj)))
yield "Done in %.3f" % (time.time()-s)
# - Tests -

View file

@ -282,8 +282,10 @@ class UiWebsocket:
# Find data in json files
def actionFileQuery(self, to, dir_inner_path, query):
# s = time.time()
dir_path = self.site.getPath(dir_inner_path)
rows = list(QueryJson.query(dir_path, query))
# self.log.debug("FileQuery %s %s done in %s" % (dir_inner_path, query, time.time()-s))
return self.response(to, rows)

View file

@ -4,12 +4,10 @@ class Loading
setProgress: (percent) ->
console.log "Progress:", percent
$(".progressbar").css("width", percent*100+"%").css("opacity", "1").css("display", "block")
hideProgress: ->
$(".progressbar").css("width", "100%").css("opacity", "0").cssLater("display", "none", 1000)
console.log "Hideprogress"
showScreen: ->

View file

@ -59,7 +59,6 @@ class Wrapper
cmd = message.cmd
if cmd == "innerReady"
@inner_ready = true
@log "innerReady", @ws.ws.readyState, @wrapperWsInited
if @ws.ws.readyState == 1 and not @wrapperWsInited # If ws already opened
@sendInner {"cmd": "wrapperOpenedWebsocket"}
@wrapperWsInited = true
@ -148,7 +147,6 @@ class Wrapper
onOpenWebsocket: (e) =>
@ws.cmd "channelJoin", {"channel": "siteChanged"} # Get info on modifications
@log "onOpenWebsocket", @inner_ready, @wrapperWsInited
if not @wrapperWsInited and @inner_ready
@sendInner {"cmd": "wrapperOpenedWebsocket"} # Send to inner frame
@wrapperWsInited = true
@ -178,7 +176,6 @@ class Wrapper
# Iframe loaded
onLoad: (e) =>
@log "onLoad"
@inner_loaded = true
if not @inner_ready then @sendInner {"cmd": "wrapperReady"} # Inner frame loaded before wrapper
#if not @site_error then @loading.hideScreen() # Hide loading screen

View file

@ -472,13 +472,11 @@ jQuery.extend( jQuery.easing,
}
Loading.prototype.setProgress = function(percent) {
console.log("Progress:", percent);
return $(".progressbar").css("width", percent * 100 + "%").css("opacity", "1").css("display", "block");
};
Loading.prototype.hideProgress = function() {
$(".progressbar").css("width", "100%").css("opacity", "0").cssLater("display", "none", 1000);
return console.log("Hideprogress");
return $(".progressbar").css("width", "100%").css("opacity", "0").cssLater("display", "none", 1000);
};
Loading.prototype.showScreen = function() {
@ -807,7 +805,6 @@ jQuery.extend( jQuery.easing,
cmd = message.cmd;
if (cmd === "innerReady") {
this.inner_ready = true;
this.log("innerReady", this.ws.ws.readyState, this.wrapperWsInited);
if (this.ws.ws.readyState === 1 && !this.wrapperWsInited) {
this.sendInner({
"cmd": "wrapperOpenedWebsocket"
@ -933,7 +930,6 @@ jQuery.extend( jQuery.easing,
this.ws.cmd("channelJoin", {
"channel": "siteChanged"
});
this.log("onOpenWebsocket", this.inner_ready, this.wrapperWsInited);
if (!this.wrapperWsInited && this.inner_ready) {
this.sendInner({
"cmd": "wrapperOpenedWebsocket"
@ -974,7 +970,6 @@ jQuery.extend( jQuery.easing,
Wrapper.prototype.onLoad = function(e) {
var _ref;
this.log("onLoad");
this.inner_loaded = true;
if (!this.inner_ready) {
this.sendInner({