Giter Club home page Giter Club logo

ssb-replication-limiter's Introduction

Build Status

ssb-replication-limiter

Limit and prioritise ebt replication for ssb.

ssb-ebt only exposes an api to stop or start replication of a feed. This module enhances it so you can control the maximum number of simultaneous downloads and prioritise who gets replicated first.

The limiter has two modes: unlimited and limited. In unlimited mode the module doesn't really do anything, it's just ordinary ebt replication.

In limited mode, only a certain number of feeds are allowed to be replicating at once.

This module tracks how far behind all feeds are. If your local copies are a long way behind then you have to do a lot of downloading to do. If a feed is more than threshold (modeChangeThreshold) behind, the module changes mode to limited mode.

In limited mode, only a set number (maxNumConnections) of feeds will be replicated simultaneously.

It's also possible to prioritise which feeds are replicated first in limited mode. See the third argument of the request function.

API

Init

var ReplicationLimiter = require('ssb-replication-limiter')
var replicationLimiter = ReplicationLimiter(opts)

Takes an opts object of shape:

{
  peerStatus: <function> (required)
  request: <function> (required)

  maxNumConnections: <num>,
  modeChangeThreshold: <num>,
}

replicationLimiter has four methods:

replicationLimiter.request(feedId, isReplicationEnabled, [priority])

Same as ssb-ebt's request method. priority is optional and defaults to 0. The higher the number, the sooner it will be replicated.

replicationLimiter.setModeChangeThreshold(threshold)

Sets a new mode change threshold.

replicationLimiter.setMaxNumConnections(max)

Sets a new maximum number of connections allowed when in limited mode.

replicationLimiter.isReplicationEnabled()

isReplicationEnabled is an observable

Sets listener-function as a new observer of isReplicationEnabled

listener-function will be called with a boolean when the mode changes.

Install

With npm installed, run

$ npm install ssb-replication-limiter

Acknowledgments

This project is funded by a grant from staltz for the manyverse project.

See Also

License

MIT

ssb-replication-limiter's People

Contributors

christianbundy avatar pietgeursen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ssb-replication-limiter's Issues

what sort of mode does the threashold change? (feedback on names)

When I was reviewing ssbc/ssb-ebt#15 I saw "setModeChangeThreashold" and was like, hang on, what sort of mode change is this threashold controlling? it took me a little while to figure out what that meant.

If a feed is behind by over a threashold (number of messages) it's switched to limited mode. maybe limitedThreashold or limitedModeThreashold would be a more obvious name?

Also, maxNumConnections, firstly "num" seems redundant because connections is plural, and "max" implies it's gonna be a number. But also, it's not actually about connections (i.e. connections to peers), it's about feeds. I'd suggest "maxLimitedFeeds" or "concurrentLimitedFeeds"

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.