minor refactor
This commit is contained in:
parent
cba25e494c
commit
a63d9578f3
32
lib/index.js
32
lib/index.js
|
@ -44,36 +44,42 @@ function initConductor(peer, config) {
|
||||||
* How many bytes does a single msg ID take up
|
* How many bytes does a single msg ID take up
|
||||||
*/
|
*/
|
||||||
const MSG_ID_BYTES = MsgV4.getMootID('dummy', 'dummy').length
|
const MSG_ID_BYTES = MsgV4.getMootID('dummy', 'dummy').length
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many bytes does an average msg take up
|
* How many bytes does an average msg take up
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_MSG_SIZE = 600 // 600 bytes
|
const ESTIMATE_MSG_SIZE = 600 // 600 bytes
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many bytes should we budget for ghost msg IDs in total in the database
|
* How many bytes should we budget for ghost msg IDs in total in the database
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_TOTAL_GHOST_BYTES = 1024 * 1024 // 1 MB
|
const ESTIMATE_TOTAL_GHOST_BYTES = 1024 * 1024 // 1 MB
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many msgs does the average 'follows' Set feed contain
|
* How many msgs does the average 'follows' Set feed contain
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_FOLLOWS_FEED_SIZE = 300
|
const ESTIMATE_FOLLOWS_FEED_SIZE = 300
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many msgs does the average 'block' Set feed contain
|
* How many msgs does the average 'block' Set feed contain
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_BLOCK_FEED_SIZE = 30
|
const ESTIMATE_BLOCK_FEED_SIZE = 30
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* How many msgs does the average unknown feed contain
|
* How many msgs does the average unknown feed contain
|
||||||
*/
|
*/
|
||||||
const ESTIMATE_FEED_SIZE = 100
|
const ESTIMATE_FEED_SIZE = 100
|
||||||
|
/**
|
||||||
|
* Absolute minimum acceptable maxBytes parameter
|
||||||
|
*/
|
||||||
const MIN_MAXBYTES = 1024 // 1 kB
|
const MIN_MAXBYTES = 1024 // 1 kB
|
||||||
const MIN_RECOMMENDED_MAXBYTES = 32 * 1024 * 1024 // 32 MB
|
/**
|
||||||
const GOOD_RECOMMENDED_MAXBYTES = 64 * 1024 * 1024 // 64 MB
|
* Lower bound for somewhat acceptable maxBytes parameter
|
||||||
const MAX_RECOMMENDED_MAXBYTES = 100 * 1024 * 1024 // 100 MB
|
*/
|
||||||
|
const MIN_DECENT_MAXBYTES = 32 * 1024 * 1024 // 32 MB
|
||||||
|
/**
|
||||||
|
* Recommended maxBytes parameter
|
||||||
|
*/
|
||||||
|
const RECOMMENDED_MAXBYTES = 64 * 1024 * 1024 // 64 MB
|
||||||
|
/**
|
||||||
|
* Upper bound for somewhat acceptable maxBytes parameter
|
||||||
|
*/
|
||||||
|
const MAX_DECENT_MAXBYTES = 100 * 1024 * 1024 // 100 MB
|
||||||
|
|
||||||
const debug = makeDebug('ppppp:conductor')
|
const debug = makeDebug('ppppp:conductor')
|
||||||
|
|
||||||
|
@ -126,9 +132,9 @@ function initConductor(peer, config) {
|
||||||
const estimateBytesUsed = estimateMsgCount * ESTIMATE_MSG_SIZE
|
const estimateBytesUsed = estimateMsgCount * ESTIMATE_MSG_SIZE
|
||||||
const factor = maxBytes / estimateBytesUsed
|
const factor = maxBytes / estimateBytesUsed
|
||||||
if (estimateBytesUsed > maxBytes) {
|
if (estimateBytesUsed > maxBytes) {
|
||||||
if (maxBytes < MIN_RECOMMENDED_MAXBYTES) {
|
if (maxBytes < MIN_DECENT_MAXBYTES) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
debug('WARNING. maxBytes is in practice too small, we recommend at least %s bytes, ideally %s bytes, and at most %s bytes', MIN_RECOMMENDED_MAXBYTES, GOOD_RECOMMENDED_MAXBYTES, MAX_RECOMMENDED_MAXBYTES)
|
debug('WARNING. maxBytes is in practice too small, we recommend at least %s bytes, ideally %s bytes, and at most %s bytes', MIN_DECENT_MAXBYTES, RECOMMENDED_MAXBYTES, MAX_DECENT_MAXBYTES)
|
||||||
} else {
|
} else {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
debug('WARNING. maxBytes might be easily surpassed, you should downscale rules to %s%', (factor*100).toFixed(0))
|
debug('WARNING. maxBytes might be easily surpassed, you should downscale rules to %s%', (factor*100).toFixed(0))
|
||||||
|
@ -207,9 +213,9 @@ function initConductor(peer, config) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
throw new Error(`ppppp-conductor maxBytes must be at least ${MIN_MAXBYTES} bytes, got ${maxBytes}`)
|
||||||
}
|
}
|
||||||
if (maxBytes > MAX_RECOMMENDED_MAXBYTES) {
|
if (maxBytes > MAX_DECENT_MAXBYTES) {
|
||||||
// prettier-ignore
|
// prettier-ignore
|
||||||
debug('WARNING. maxBytes is too big, we recommend at most %s bytes', MAX_RECOMMENDED_MAXBYTES)
|
debug('WARNING. maxBytes is too big, we recommend at most %s bytes', MAX_DECENT_MAXBYTES)
|
||||||
}
|
}
|
||||||
|
|
||||||
const follows = peer.set.values('follows')
|
const follows = peer.set.values('follows')
|
||||||
|
|
Loading…
Reference in New Issue