Skip to content

Instantly share code, notes, and snippets.

@dominictarr
Created November 9, 2015 02:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominictarr/60e3b069858b49e97db2 to your computer and use it in GitHub Desktop.
Save dominictarr/60e3b069858b49e97db2 to your computer and use it in GitHub Desktop.
sbot profile

profile script

test script to measure perf on querying sbot. pull from the user stream, filter by top level posts, and then join with replies and votes. (just to get enough to render the post)

optional: disable related to use links to get a count of the replies & votes, instead of the relatedMessages, which is recursive.

call like this:

node profile.js @hxGxqPrplLjRG2vtjQL87abX4QKqeLgCwQpS730nNwE=.ed25519

output will be the posts, and the number of messages returned, scanned, and the elapsed time of the query (not including node startup time)

var fs = require('fs')
var ssbc = require('ssb-client')
var pull = require('pull-stream')
var paramap = require('pull-paramap')
var related = false
//scan
ssbc(function (err, sbot) {
if(err) throw err
var start = Date.now()
var c = 0
pull(
sbot.createUserStream({reverse: true, id: process.argv[2]}),
pull.filter(function (data) {
c++
return (
data.value.content.type === 'post'
&& !data.value.content.root
)
}),
pull.take(30),
( related
? paramap(function (data, cb) {
sbot.relatedMessages({id: data.key, count: true}, cb)
}, 16)
: pull(
paramap(function (data, cb) {
pull(
sbot.links({dest: data.key, rel: 'root'}),
pull.collect(function (err, links) {
data.replies = links
cb(null, data)
})
)
}, 16),
paramap(function (data, cb) {
pull(
sbot.links({dest: data.key, rel: 'vote'}),
pull.collect(function (err, links) {
data.votes = links
cb(null, data)
})
)
}, 16)
)
),
pull.collect(function (err, ary) {
if(err) throw err
console.log('output'),
console.log(ary)
console.log('found, scanned, elapsed (ms)')
console.log([ary.length, c, Date.now() - start].join(', '))
sbot.close(true)
})
)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment