Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sloki

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sloki

A NodeJS server for LokiJS

  • 0.0.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Sloki

A NodeJS Server for LokiJS

:hammer: :hammer: :hammer: :hammer: :hammer: WORK IN PROGRESS :hammer: :hammer: :hammer: :hammer: :hammer:

alt CI-badge npm version Known Vulnerabilities Dependencies Dev Dependencies


Documentation

  1. Introduction
    1. Transports
    2. Protocols
      1. Binary (default)
      2. JSONRPC
  2. Installation

1. Introduction

Sloki is a nodejs server which embed LokiJS, a blazing fast in-memory documents database. Sloki help to make LokiJS scalable : you can now have multiple processes speaking with LokiJS through Sloki.

A possible architecture using sloki :


    +----------------------------+    TCP / Binary     +-----------------------------------+
    |   NodeJS app worker #1     |<------------------->|                                   |
    +----------------------------+                     |               Sloki               |
                                                       |                                   |
    +----------------------------+    TCP / Binary     |    +-------------------------+    |
    |  NodeJS app worker #2      |<------------------->|    |                         |    |
    +----------------------------+                     |    |                         |    |
                                                       |    |         LokiJS          |    |
    +----------------------------+    TCP / JSONRPC    |    | fast in-memory database |    |
    | go/php/python/C/whatever   |<------------------->|    |                         |    |
    +----------------------------+                     |    |                         |    |
                                                       |    |                         |    |
    +----------------------------+    TCP / Binary     |    +-------------------------+    |
    |        sloki-cli           |<------------------->|                                   |
    +----------------------------+                     +-----------------------------------+

1.i. Transports

For moment, only TCP transport is supported. The advantage of TCP vs HTTP API is that the connection is persistent.

By default, Sloki listens on the following ports:

PortTransportTLSProtocolops/sec/client
6370TCPNOBinary (fastest)avg 18K ops/sec
6371TCPYESBinary (fastest)avg 25K ops/sec (??)
6372TCPNOJSONRPCavg 17K ops/sec
6373TCPYESJSONRPCavg 24K ops/sec (??)

If somebody have an idea why TLS is fastest than TCP, i'd like to know .. :)

You will need a client to speak with sloki.

1.ii. Protocols

1.ii.a. Binary protocol (default)

The binary protocol has been made with performance in mind. Payloads looks like JSONRPC, but it's not.

REQUEST                                     | RESPONSE
------------------------------------------- | --------------------------------------
{                                           | {
    "m":"myMethod",                         |   "r":true,
    "p":["foo","bar"],                      |   "id":"operation-uniq-id"
    "id":"operation-uniq-id"                | }
}                                           |
  • Payload is a little lighter compared to compliant JSONRPC protocol described below (i.e no jsonrpc version attribute, method become m, params become p, result become r)
  • Missive package is used both server and client side to transform payloads into a binary format. Missive support zlib compression, but it's not used here and it's not recommended because of performance crumble. Missive is based on fringe, an extensible message framing over streams for nodejs.

1.ii.b. JSONRPC

The JSONRPC protocol has been chosen for interoperability.

REQUEST                                     | RESPONSE
------------------------------------------- | --------------------------------------
{                                           | {
    "jsonrpc":"2.0",                        |   "jsonrpc":"2.0"
    "method":"myMethod",                    |   "result":true,
    "params":["foo","bar"],                 |   "id":"operation-uniq-id"
    "id":"operation-uniq-id"                | }
}                                           |
  • Raw and standard JSONRPC over TCP
  • jayson package is used server side. Actually only TCP transport is implemented, but HTTP(s) JSON API and websocket API may be implemented in the future.

Server Installation

  • npm install -g sloki

Server Usage

  • sloki
  • sloki --help

Client

See https://github.com/sloki-project/sloki-node-client

The client will load every methods that sloki server have, so, the client documentation is not really usefull

Benchmarks

See https://github.com/sloki-project/sloki-benchs

Development status

Legends
IconDescription
:heavy_check_mark:implemented
:heavy_plus_sign:in progress/MUST be implemented
:red_circle:does NOT make sens in sloki, will NOT be implemented
:question:MAY be implemented
Transports

StatusTransportNotes
:heavy_check_mark:TCPPersistant connection
:heavy_plus_sign:TLSPersistant connection
:question:HTTP
:question:HTTPS

Methods: client and server related

StatusMethodParameterDescription
:heavy_check_mark:clientsreturn TCP/TLS connected clients
:heavy_check_mark:gcinvoke gc(), for testing purpose
:heavy_check_mark:maxClientsreturn TCP/TLS maxClients
:heavy_check_mark:maxClientsmaxClientsset TCP/TLS maxClients
:heavy_check_mark:memoryreturn sloki memory usage
:heavy_check_mark:methodsreturn sloki methods
:heavy_check_mark:quitdisconnect (TCP/TLS clients only)
:heavy_check_mark:shutdownshutdown sloki
:heavy_check_mark:versionreturn versions (sloki, lokijs, sloki-node-client)
:heavy_check_mark:waitwait for one second, for testing purpose

Methods: database related

Loki Class (Database) documentation

StatusCommandParameter(s)Description
:heavy_check_mark:loadDatabasedatabaseName,[options]select (and load if needed) a database
:heavy_check_mark:dbreturn current database name (sloki specific)
:heavy_check_mark:listDatabasesreturn available databases
:heavy_check_mark:saveDatabasetrigger manual saving of the selected database
:heavy_check_mark:listCollectionsreturn available collections in selected database
:heavy_check_mark:addCollectionoptionsadd a collection in selected database
:heavy_check_mark:getCollectioncollectionNamereturn collection properties in selected database
:heavy_plus_sign:removeCollectioncollectionNameremoves a collection from the selected database
:heavy_plus_sign:renameCollectionoldName, newNamerenames an existing collection in the selected database
:question:clearChangesclears all the changes in all collections of selected database
:question:closeclose selected database
:question:configureOptionsoptionsreconfigure selected database options
:question:copyoptionscopy selected database into a new Loky instance
:question:deleteDatabasedelete selected database
:question:getCollectioncollectionNameRetrieves reference to a collection by name
:red_circle:deserializeCollectionsee LokiJS Class documentation
:red_circle:deserializeDestructuredsee LokiJS Class documentation
:red_circle:generateChangesNotificationsee LokiJS Class documentation
:red_circle:loadDatabasesee "use" command
:red_circle:loadJSONsee LokiJS Class documentation
:red_circle:loadJSONObjectsee LokiJS Class documentation
:red_circle:serializesee LokiJS Class documentation
:red_circle:serializeChangessee LokiJS Class documentation
:red_circle:serializeCollectionoptionssee LokiJS Class documentation
:red_circle:serializeDestructuredoptionssee LokiJS Class documentation
:red_circle:throttledSaveDrainsee LokiJS Class documentation

Methods: collection related

Loki Collection documentation

StatusCommandParameter(s)Description
:heavy_check_mark:findcollectionName, filterfind document(s)
:heavy_check_mark:getcollectionName, lokiIdreturn a document by his id
:heavy_check_mark:insertcollectionName, documentinsert one or more document(s)
:heavy_check_mark:removecollectionName, document or idremove one or more document(s)
:heavy_check_mark:updatecollectionName, documentupdate a document

Benchmarks

StatusTransportNotes
:heavy_plus_sign:TCPPersistant connection
:heavy_plus_sign:TLSPersistant connection
:question:HTTP
:question:HTTPS

Tools

StatusToolNotes
:heavy_plus_sign:CLICLI using TCP transport

Improvements on top of LokiJS

StatusImprovementNotes
:heavy_plus_sign:AuthenticationOptional authentication layer (all transports)


Server options

$ sloki --help

=======================================================================
              Sloki - a NodeJS Server for LokyJS
=======================================================================
 Environnement variable             Default
   SLOKI_TCP_BINARY_ENABLE         true
   SLOKI_TCP_BINARY_PORT           6370
   SLOKI_TCP_BINARY_HOST           localhost
   SLOKI_TCP_BINARY_MAX_CLIENTS    64
   SLOKI_TLS_BINARY_ENABLE         true
   SLOKI_TLS_BINARY_PORT           6371
   SLOKI_TLS_BINARY_HOST           localhost
   SLOKI_TLS_BINARY_MAX_CLIENTS    64
   SLOKI_TCP_JSONRPC_ENABLE        true
   SLOKI_TCP_JSONRPC_PORT          6372
   SLOKI_TCP_JSONRPC_HOST          localhost
   SLOKI_TCP_JSONRPC_MAX_CLIENTS   64
   SLOKI_TLS_JSONRPC_ENABLE        true
   SLOKI_TLS_JSONRPC_PORT          6373
   SLOKI_TLS_JSONRPC_HOST          localhost
   SLOKI_TLS_JSONRPC_MAX_CLIENTS   64
   SLOKI_DIR                       /home/franck/.sloki
   SLOKI_SHOW_OPS_INTERVAL         0
   SLOKI_GC_INTERVAL               3600000
   SLOKI_MEM_LIMIT                 26094 Mb
-----------------------------------------------------------------------
 Command Line Options               Default
   --tcp-binary-enable             true
   --tcp-binary-port               6370
   --tcp-binary-host               localhost
   --tcp-binary-max-clients        64
   --tls-binary-enable             true
   --tls-binary-port               6371
   --tls-binary-host               localhost
   --tls-binary-max-clients        64
   --tcp-jsonrpc-enable            true
   --tcp-jsonrpc-port              6372
   --tcp-jsonrpc-host              localhost
   --tcp-jsonrpc-max-clients       64
   --tls-jsonrpc-enable            true
   --tls-jsonrpc-port              6373
   --tls-jsonrpc-host              localhost
   --tls-jsonrpc-max-clients       64
   --dir                           /home/franck/.sloki
   --show-ops-interval             0
   --gc-interval                   3600000
   --mem-limit                     26094 Mb
-----------------------------------------------------------------------
Examples:
$ sloki     # will use defaults
$ sloki --tcp-binary-port=6370 --tcp-binary-host=localhost

The default values ​​can be overridden first with those of the environment variables, and then those of the command line options.

  • SLOKI_DIR /path/to/sloki

    • default is user's home (~user/.sloki)
    • subdirectory dbs contains lokijs databases
    • subdirectory certs contains SSL Certificates for TLS
    • directories will be created if not exist
  • SLOKI_MEM_LIMIT

    • by default, 80% of the available memory
  • SLOKI_GC_INTERVAL

    • run nodejs garbage collector at regular interval (value in milliseconds)

Keywords

FAQs

Package last updated on 23 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc