more detailed connection statistics, first char recv bugfix, double connection bugfix, websocket send queue, loading screen hide bugfix on slow connection, disable user reload
This commit is contained in:
parent
31d4609a3b
commit
e8368a8da1
10 changed files with 131 additions and 56 deletions
|
@ -276,22 +276,54 @@ class UiRequest:
|
|||
raise Exception("Here is your console")
|
||||
|
||||
|
||||
def formatTableRow(self, row):
|
||||
back = []
|
||||
for format, val in row:
|
||||
if val == None:
|
||||
formatted = "n/a"
|
||||
elif format == "since":
|
||||
if val:
|
||||
formatted = "%.0f" % (time.time()-val)
|
||||
else:
|
||||
formatted = "n/a"
|
||||
else:
|
||||
formatted = format % val
|
||||
back.append("<td>%s</td>" % formatted)
|
||||
return "<tr>%s</tr>" % "".join(back)
|
||||
|
||||
def actionStats(self):
|
||||
import gc, sys
|
||||
from greenlet import greenlet
|
||||
greenlets = [obj for obj in gc.get_objects() if isinstance(obj, greenlet)]
|
||||
self.sendHeader()
|
||||
main = sys.modules["src.main"]
|
||||
yield """
|
||||
<style>
|
||||
* { font-family: monospace }
|
||||
table * { text-align: right; padding: 0px 10px }
|
||||
</style>
|
||||
"""
|
||||
|
||||
yield "<pre>"
|
||||
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>"
|
||||
for connection in main.file_server.connections:
|
||||
yield "%s: %s %s<br>" % (connection.protocol, connection.ip, connection.zmq_sock)
|
||||
yield self.formatTableRow([
|
||||
("%3d", connection.id),
|
||||
("%s", connection.protocol),
|
||||
("%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)),
|
||||
("%.3f", connection.last_sent_time-connection.last_send_time),
|
||||
("%.0fkB", connection.bytes_sent/1024),
|
||||
("%.0fkB", connection.bytes_recv/1024)
|
||||
])
|
||||
yield "</table>"
|
||||
|
||||
yield "Greenlets (%s):<br>" % len(greenlets)
|
||||
for thread in greenlets:
|
||||
yield " - %s<br>" % cgi.escape(repr(thread))
|
||||
yield "</pre>"
|
||||
|
||||
|
||||
# - Tests -
|
||||
|
|
|
@ -15,6 +15,8 @@ class UiWebsocket:
|
|||
self.next_message_id = 1
|
||||
self.waiting_cb = {} # Waiting for callback. Key: message_id, Value: function pointer
|
||||
self.channels = [] # Channels joined to
|
||||
self.sending = False # Currently sending to client
|
||||
self.send_queue = [] # Messages to send to client
|
||||
|
||||
|
||||
# Start listener loop
|
||||
|
@ -69,10 +71,16 @@ class UiWebsocket:
|
|||
def send(self, message, cb = None):
|
||||
message["id"] = self.next_message_id # Add message id to allow response
|
||||
self.next_message_id += 1
|
||||
if cb: # Callback after client responsed
|
||||
self.waiting_cb[message["id"]] = cb
|
||||
if self.sending: return # Already sending
|
||||
self.send_queue.append(message)
|
||||
try:
|
||||
self.ws.send(json.dumps(message))
|
||||
if cb: # Callback after client responsed
|
||||
self.waiting_cb[message["id"]] = cb
|
||||
while self.send_queue:
|
||||
self.sending = True
|
||||
message = self.send_queue.pop(0)
|
||||
self.ws.send(json.dumps(message))
|
||||
self.sending = False
|
||||
except Exception, err:
|
||||
self.log.debug("Websocket send error: %s" % Debug.formatException(err))
|
||||
|
||||
|
@ -177,7 +185,7 @@ class UiWebsocket:
|
|||
"next_size_limit": site.getNextSizeLimit(),
|
||||
"last_downloads": len(site.last_downloads),
|
||||
"peers": site.settings.get("peers", len(site.peers)),
|
||||
"tasks": len([task["inner_path"] for task in site.worker_manager.tasks]),
|
||||
"tasks": len(site.worker_manager.tasks),
|
||||
"content": content
|
||||
}
|
||||
if site.settings["serving"] and content: ret["peers"] += 1 # Add myself if serving
|
||||
|
|
|
@ -249,6 +249,10 @@ class Wrapper
|
|||
@ws.cmd "siteSetLimit", [site_info.next_size_limit], (res) =>
|
||||
@notifications.add("size_limit", "done", res, 5000)
|
||||
return false
|
||||
|
||||
if @loading.screen_visible and @inner_loaded and site_info.settings.size < site_info.size_limit*1024*1024 # Loading screen still visible, but inner loaded
|
||||
@loading.hideScreen()
|
||||
|
||||
@site_info = site_info
|
||||
|
||||
|
||||
|
|
|
@ -1057,6 +1057,9 @@ jQuery.extend( jQuery.easing,
|
|||
})(this));
|
||||
}
|
||||
}
|
||||
if (this.loading.screen_visible && this.inner_loaded && site_info.settings.size < site_info.size_limit * 1024 * 1024) {
|
||||
this.loading.hideScreen();
|
||||
}
|
||||
return this.site_info = site_info;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue