Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
725d596
fix: installation steps in README
techsavvyash Jan 13, 2024
44e646d
Words and command were not properly defined in customEval cli.js
rahul-shrimali Jan 21, 2024
ad52775
Merge pull request #1 from rahul-shrimali/improveGet_Set
techsavvyash Jan 21, 2024
1ef5153
chore: refactor
techsavvyash Jan 28, 2024
55722b6
feat: setup server and refactor code
techsavvyash Feb 9, 2024
968d787
docs: update README, TODO AND CONTRIBUTING .mds
techsavvyash Feb 9, 2024
fd1c6b3
changes regarding message in server.js
rahul-shrimali Feb 12, 2024
7f1359b
feat(wip): changes
techsavvyash Feb 24, 2024
304b071
merge
techsavvyash Feb 25, 2024
e7a4dd0
fix(maybe): append_fail error
techsavvyash Feb 25, 2024
d89ebd8
feat(wip): figure out get set
techsavvyash Feb 27, 2024
074f22c
Initial configuration of set
rahul-shrimali Feb 27, 2024
29025c3
set resolve errors
rahul-shrimali Feb 28, 2024
d9cc375
Closing the db on EXIT command
rahul-shrimali Feb 28, 2024
f00c254
sequential calls for set
rahul-shrimali Feb 28, 2024
1a9d084
Merge pull request #2 from techsavvyash/dev
techsavvyash Feb 28, 2024
53ee440
feat(maybe unstable): get func for leader
techsavvyash Feb 28, 2024
d17224f
get client implementation
rahul-shrimali Feb 28, 2024
67b661f
working get and set on all nodes
rahul-shrimali Feb 28, 2024
ad77243
fix: allow for multiple socket writes at a time
techsavvyash Mar 12, 2024
905c245
fix: working get set and node consensus
techsavvyash Mar 13, 2024
88d2a58
Merge pull request #3 from techsavvyash/dev
techsavvyash Mar 13, 2024
b444812
feat: get proxy working, fix the clients and make sure everything works
techsavvyash Mar 13, 2024
272aa66
resolve bug of data not being set in batches
rahul-shrimali Mar 14, 2024
8d0bfbb
Another connection bug resolved
rahul-shrimali Mar 17, 2024
d166c85
get using one node only
rahul-shrimali Mar 18, 2024
3d8228e
Merge pull request #5 from techsavvyash/dev
techsavvyash Mar 19, 2024
d98dbb2
feat: setup mprocs
techsavvyash Mar 28, 2024
3d3d88e
feat: non race conditions working impl
techsavvyash Mar 29, 2024
4c8da23
Merge pull request #6 from techsavvyash/dev
techsavvyash Mar 29, 2024
bfb176f
idk what's going on
techsavvyash Mar 29, 2024
c8f7290
feat: we finally have a folder structure
techsavvyash Mar 29, 2024
e651d31
Merge pull request #7 from techsavvyash/dev
techsavvyash Mar 29, 2024
0bfc55e
feat: more refactoring
techsavvyash Mar 30, 2024
80dc785
feat: add simdjson for JSON.parse
techsavvyash Mar 30, 2024
944cdc9
Merge pull request #8 from techsavvyash/dev
techsavvyash Mar 30, 2024
439c923
docs: update README (still needs work but has basics out the way)
techsavvyash Mar 30, 2024
a272c04
feat: try adding benchmarking
techsavvyash Mar 30, 2024
c0decba
Completed benchmark.js
rahul-shrimali Apr 1, 2024
4ae6e81
graph for json
rahul-shrimali Apr 2, 2024
4132fbe
fix: benchmark and comment out simd
techsavvyash Apr 3, 2024
8514625
Merge branch 'dev' of https://github.com/techsavvyash/stylusdb-js int…
techsavvyash Apr 3, 2024
df70b5e
Merge pull request #13 from techsavvyash/dev
techsavvyash Apr 3, 2024
2c82110
feat: setup gitpod
techsavvyash Apr 3, 2024
fc4d8ac
fix: update benchmark.js
techsavvyash Apr 4, 2024
48db276
docs: new graphs
techsavvyash Apr 4, 2024
7506956
fix: redundant packages
techsavvyash Apr 22, 2024
979873d
feat: simd benchmarks
techsavvyash Apr 26, 2024
b4927cd
docs: add README for appendix
techsavvyash Apr 26, 2024
1143908
fix: file names in appendix
techsavvyash Apr 26, 2024
5589266
chore: changes
techsavvyash Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
node_modules
db
log
log
benchmarks
data

commit-errors.txt
events.json
11 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This configuration file was automatically generated by Gitpod.
# Please adjust to your needs (see https://www.gitpod.io/docs/introduction/learn-gitpod/gitpod-yaml)
# and commit this file to your remote git repository to share the goodness with others.

# Learn more from ready-to-use templates: https://www.gitpod.io/docs/introduction/getting-started/quickstart

tasks:
- init: npm install
command: npm run prepare && npm run start:dev


2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.19.0
v18.18.0
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
35 changes: 35 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# StylusDB

## Project Structure

This project is a normal NodeJS project with a target of using as less NPM dependencies as much possible.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May not be the goal here. Building the fastest JS implementation is.


### Directories

- [`./raft`](./raft/) - This directory contains a very light weight implementation of the Raft Protocol. The code inside this folder has been taken from [unshitio/liferaft](https://github.com/unshiftio/liferaft)
- [`./reference`](./reference/) - This folder is for experimentation purposes this is where the contributors store the code for WIP experiments which are to be referenced later.
- [`./scripts`](./scripts/) - This folder contains a few scripts to avoid the hassle of manually running the cluster and clients

### Files

- [`./cli.js`](./cli.js) - This file contains the implementation for a minimalistic REPL or CLI for StylusDB cause what is a DB without a CLI 🤓.
- [`./client.js`](./client.js) - This is a small implementation of a sample client to send messages to the nodes in the cluster.
- [`./db.js`](./db.js) - This contains the implementation for connecting and storing data to our storage engine. Presently this acts as an interface to `LMDB` but in future this will be a generic interface to a host of storage engines.
- [`./index.js`](./index.js) - Contains the implementation of the class defining the structure and callbacks for a node in the `StylusDB` Raft Node Cluster.
- [`./raft-node.js`](./raft-node.js) - This file contains functions to instantiate a node using the class defined in index.js. This exists as a separate file for ease of understanding right now, might be merged with `index.js` later.
- [`./server.js`](./server.js) - This file setsup a server to accept connections and respond to requests from client. This is the file where the Raft Node is instantiated and connected to the other nodes in the cluster.

## How to Contribute?
- Refer to issue tickets on [Github](https://github.com/techsavvyash/stylusdb-js)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change remote

- A list of high level goals and roadmap can be found in [TODO.md](./TODO.md)
- Rest of the steps remain same as how you'd contribute to any other open source project
- Fork the repository
- Make the required changes
- Raise a PR and ask for reviews
- In case of doubts or guidance reach out to [Yash Mittal](https://github.com/techsavvyash)

## Pre-requisties
- Understanding of the [Raft Distributed Consensus Algorithm](ft.github.io/raft.pdf)
- Working knowledge of [NodeJS](https://nodejs.com)
- Knowledge of Distributed Systems and Distributed Databases
- Knowledge of Database Internals
38 changes: 22 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,46 +1,52 @@
# stylusdb-js

A minimalistic implementation of a distributed KV Store
A minimalistic implementation of a distributed KV Store based on the Raft consensus protocol. StylusDB aims to be a SOTA JS implementation of a RAFT based highthrouput KV.

### Configuration
Modify config.json
Modify `config.json`

### Installation
```sh
nvm install 16
nvm use 16
nvm install 18
nvm use 18
npm install
```

### Preparing Directories

Create the following 6 directories before contiuing to start the server below:
```bash
mkdir db log
```


### Starting Server
Open four terminals and start a 4 node cluster.

```sh
DEBUG=* node index.js --port 8081
DEBUG=* node index.js --port 8082
DEBUG=* node index.js --port 8083
DEBUG=* node index.js --port 8084
npm run start
```

This will start a 4 node raft cluster, a proxy server and a user-shell in a [mprocs](https://github.com/pvolok/mprocs) tui for you to develop easily.


### Benchmarks
Coming soon
Coming soon

### REPL
Coming soon
Coming soon (WIP with [ClI](./cli.js))

### TODOs
- [ ] Dockerization
- [ ] Memory profiling
- [ ] Scripts to deploy to edge
- [ ] Client implementation
- [ ] Integrate YCSB
- [ ] Java based
- [ ] Go based (because TiKV uses this to benchmark themselves)

### Caveats
1. WIP (Bleeding edge) - use it at your own risk.
2. Built for learning puposed only

### Contribution
1. Project is actively looking for contributors. Look at open tickets

2. Built for learning puposes only

### References
1. [REPL](https://gist.github.com/goliatone/e8f38b75aa05b2d189f68a92c61af110)
Expand Down
5 changes: 0 additions & 5 deletions config.json

This file was deleted.

9 changes: 9 additions & 0 deletions config/mprocs.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
procs:
raft-node-1:
shell: "node ./src/server.js --port 8081"
raft-node-2:
shell: "node ./src/server.js --port 8082"
raft-node-3:
shell: "node ./src/server.js --port 8083"
raft-node-4:
shell: "node ./src/server.js --port 8084"
13 changes: 13 additions & 0 deletions config/mprocs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
procs:
raft-node-1:
shell: "node ./src/server.js --port 8081"
raft-node-2:
shell: "node ./src/server.js --port 8082"
raft-node-3:
shell: "node ./src/server.js --port 8083"
raft-node-4:
shell: "node ./src/server.js --port 8084"
proxy:
shell: "node ./src/proxy.js"
user-shell:
cmd: ["zsh"]
72 changes: 0 additions & 72 deletions db.js

This file was deleted.

26 changes: 26 additions & 0 deletions docs/PROTOCOL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# StylusDB Protocol

This is a set of rules that we use to distinguish between different kinds of messages we are sending.

## Proxy
This defines the types of messages we need in the proxy.
We use the '\n' as the delimiter for the messages

### 1. Request from Client

Legend: "?"

### 2. Response from Cluster Node

Legend: "+"


### 3. Information response from Cluster Node





## Raft Node Server
- Normal raft node data/commands
- Information Requests -- information about who is the current cluster leader and how to figure out which nodes are alive and which are not ; how many members are a member of the cluster
51 changes: 51 additions & 0 deletions docs/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# TODO

## Resources
To browse the DB: https://www.mdbopener.com/
-- Refer: Pelican -- This is rebuilding Pelican in JS

## Roadmap / Things to try out

- [ ] Turn message saving into a batch process
- [ ] Fine tune `server.js` to expose set and get via CLI
- [ ] Turn setInterval directly via sockets
- [ ] Fine tune LMDB Manager
- [ ] Compress commands together and in memory calculate the final process
- [ ] Let candidates run the `GET` commands
- [ ] Make sure there are no race conditions here
- [ ] Run RAFT on the browser - [Mozilla Docs on Socket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
- [ ] Demo with message inter-play between nodes and other benchmarking
- [ ] Large Keys and Small Keys optimisation



## Doubts :-
- [ ] In message of raft when we are sending "SET" as what it should be giving error as in raft.on("data", packet) the packet is bound to be an object which is not so in this case, (sending message in server is ambiguous, the what must be in the form of a raft packet)

- [ ] When we send a message from follower to leader to set a value, there is no case to command all followers to save that message



## List -- 27/03/24

- [ ] Implement the orchestrator
- [ ] Fix the key skipping error
- [ ] Add the load balancer -- figure out if proxy can do it on its on or if we need a dedicated load balancer
- [ ] Implement updating Get-Set based on keys in a batch
- [ ] Figure out batch size -- because we get already connected error


## Observations

- we get pauses in between sets -- is there a settimeout in teh -- log entries/indexes are getting mised
- figure out why are log entries are not getting updated and throwing not found error.
- make the proxy connect to all the nodes in the cluster
make this fault tolerant so that there is a exponential retry incase some node goes off
- edit the "leader" fn to send a message to the proxy when the leader changes for it to know who the current leader is
- implement a sort of load balancing to delegate requests between the raft nodes
- figure out vs-code crashing with a lot of requests -- better memory management for the app maybe?

## question

- Load Balancing -- Should we have a separate load balancer? or is rotating queries at a proxy level enough?
- Bug: Data is not being stored between restarts
9 changes: 9 additions & 0 deletions docs/appendix/runtimes/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Response Times

This folder contains the response time of each request that is sent out during the testing for reference purposes.


| File Name | Description | Link to file
|-----------|-------------|-------------
| `set_simd_1000.json`| Response times for each SET request in the batch of 1000 requests | [Link](./set_simd_1000.json) |
| `get_simd_1000.json`| Response times for each GET request in the batch of 1000 requests | [Link](./get_simd_1000.json) |
Loading