forked from cory/tildefriends
		
	Tweaking memory stats and trying to figure out why startup got so much slower.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3828 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
		
							
								
								
									
										11
									
								
								core/ssb.js
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								core/ssb.js
									
									
									
									
									
								
							@@ -33,7 +33,7 @@ function following(db, id) {
 | 
			
		||||
			}
 | 
			
		||||
			f.sequence = row.sequence;
 | 
			
		||||
		});
 | 
			
		||||
	f.users = Array.from(f.users);
 | 
			
		||||
	f.users = Array.from(f.users).sort();
 | 
			
		||||
	var j = JSON.stringify(f);
 | 
			
		||||
	if (o != j) {
 | 
			
		||||
		db.set(id + ":following", j);
 | 
			
		||||
@@ -55,11 +55,7 @@ function followingDeep(db, seed_ids, depth) {
 | 
			
		||||
function get_latest_sequence_for_author(author) {
 | 
			
		||||
	var sequence = 0;
 | 
			
		||||
	ssb.sqlStream(
 | 
			
		||||
		'SELECT MIN(a.sequence) FROM messages a LEFT OUTER JOIN messages b ON a.author = b.author AND a.sequence + 1 = b.sequence WHERE a.author = ?1 AND b.content IS NULL',
 | 
			
		||||
		// TODO: Should we never have allowed inserting if we couldn't
 | 
			
		||||
		// validate previous?  The query above helps us fill in gaps in
 | 
			
		||||
		// feeds.
 | 
			
		||||
		//'SELECT MAX(sequence) AS sequence FROM messages WHERE author = ?1',
 | 
			
		||||
		'SELECT MAX(sequence) AS sequence FROM messages WHERE author = ?1',
 | 
			
		||||
		[author],
 | 
			
		||||
		function(row) {
 | 
			
		||||
			if (row.sequence) {
 | 
			
		||||
@@ -212,7 +208,8 @@ function ebtReplicateSendClock(request, have) {
 | 
			
		||||
	var ids = followingDeep(g_database, [me], 2).concat([request.connection.id]);
 | 
			
		||||
	if (!Object.keys(last_sent).length) {
 | 
			
		||||
		for (let id of ids) {
 | 
			
		||||
			message[id] = get_latest_sequence_for_author(id);
 | 
			
		||||
			var sequence = get_latest_sequence_for_author(id);
 | 
			
		||||
			message[id] = sequence ? sequence : -1;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	for (let id of Object.keys(have)) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1004,7 +1004,9 @@ static void _tf_ssb_connection_rpc_recv(tf_ssb_connection_t* connection, uint8_t
 | 
			
		||||
	connection->ssb->rpc_in++;
 | 
			
		||||
	if (flags & k_ssb_rpc_flag_json)
 | 
			
		||||
	{
 | 
			
		||||
		printf("RPC RECV flags=%x RN=%d: %.*s\n", flags, request_number, (int)size, message);
 | 
			
		||||
		char id[k_id_base64_len] = "";
 | 
			
		||||
		tf_ssb_id_bin_to_str(id, sizeof(id), connection->serverpub);
 | 
			
		||||
		printf("RPC RECV from %s flags=%x RN=%d: %.*s\n", id, flags, request_number, (int)size, message);
 | 
			
		||||
		JSContext* context = connection->ssb->context;
 | 
			
		||||
		JSValue val = JS_ParseJSON(context, (const char*)message, size, NULL);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -725,13 +725,14 @@ static JSValue _tf_task_getStats(JSContext* context, JSValueConst this_val, int
 | 
			
		||||
 | 
			
		||||
	JS_SetPropertyStr(context, result, "idle_percent", JS_NewFloat64(context, task->idle_percent));
 | 
			
		||||
 | 
			
		||||
	uint64_t total_memory = uv_get_total_memory();
 | 
			
		||||
	size_t rss;
 | 
			
		||||
	if (uv_resident_set_memory(&rss) == 0)
 | 
			
		||||
	{
 | 
			
		||||
		JS_SetPropertyStr(context, result, "rss", JS_NewInt64(context, rss));
 | 
			
		||||
		JS_SetPropertyStr(context, result, "memory_percent", JS_NewFloat64(context, 100.0f * rss / total_memory));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	JS_SetPropertyStr(context, result, "sqlite3_mem_used", JS_NewInt64(context, sqlite3_memory_used()));
 | 
			
		||||
	JS_SetPropertyStr(context, result, "sqlite3_memory_percent", JS_NewFloat64(context, 100.0f * sqlite3_memory_used() / total_memory));
 | 
			
		||||
 | 
			
		||||
	if (task->_ssb)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user