• Stars
    star
    54
  • Rank 544,815 (Top 11 %)
  • Language
    Erlang
  • License
    Apache License 2.0
  • Created over 11 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

simple persistent queues for Erlang

Embeddable Simple Queue

The library implements persistent queue data structure for Erlang applications.

Build Status Coverage Status Hex.pm Hex Downloads

Inspiration

Queuing is an essential features required to implement scalable and fault tolerant applications. Any asynchronous communication is build around queues. There are various queuing systems on the market RabbitMQ, Kafka, AWS SQS, AWS Kinesis, etc. Each Erlang process has in-memory queue -- mailbox. Sometimes, persistence of messages is required for robustness and reliability. The library implements embeddable queue (data structure) with message persistence that enhances traditional mailbox features of Erlang processes.

Getting started

The latest version of the library is available at its master branch. All development, including new features and bug fixes, take place on the master branch using forking and pull requests as described in contribution guidelines.

Installation

The stable library release is available via hex packages, add the library as dependency to rebar.config

{deps, [esq]}.

Usage

The library exposes public interface through exports of esq.erl module. Just call required function with required arguments, check out Key features for details.

Build library and run the development console

make
make run

Key features

Queue-compatible interface

The library implements mutable queue data structure due to file I/O. The data structure is a product of in-memory head and on-disk persistent tail. The head is kept in memory using dequeue data structure. It's capacity is limited to C messages. The disk queue is built as chain of files (64MB each segment). The queue rotates file segment when head is fully consumed by application.

Let's take a short tour to the queue interface

%%
%% create an empty queue data structure
{ok, Q} = esq:new("/tmp/q").

%%
%% enqueue the message to queue, it returns a new copy of the queue.
ok = esq:enq(a, Q).

%%
%% enqueue multiple messages to queue
[esq:enq(X, Q) || X <- [b, c, d, e]].


%%
%% dequeue message(s) from queue, it returns a list of elements
%% each element is the map #{payload => payload()} that carries payload 
%% and other message properties
[#{payload := a}] = esq:deq(Q).

%%
%% dequeue multiple messages from queue
_ = esq:deq(4, Q).

Message persistency

Queue persistency uses sequential disk I/O. It implements a queue as collection of file segments. Messages are appended to last file segments during enqueue operation and read from first segment.

         head             tail                                
         +----------+     +---+   +---+       +---+            
deq <----+    C     <-----+ q |   | q |  ...  | q <-------+ enq
         +----------+     +---+   +---+       +---+            
                             ro      ro          wr

|-----( in-memory )-----|---------( on-disk )---------| 

Any point of time a segment is either open for write or read. Segments are rotated with a frequency defined by time-to-sync (tts) timer. Note this timer might cause and invisibility of overflow message if dequeue rate is higher then enqueue. The queue always writes message to last disk segment.

In-flight capabilities

A message is in-flight after it's dequeue from a queue by a consumer, but not yet acknowledged. There is no guarantee in distributed system that the consumer receive and process message. Thus, the consumer must explicitly acknowledge message using its receipt identity.

         head             tail                                
         +----------+     +---+   +---+       +---+            
deq <-+--+    C     <-----+ q |   | q |  ...  | q <-------+ enq
      |  +----------+     +---+   +---+       +---+            
      |   ^                  ro      ro          wr            
      |   |                                                    
      |  ++---------+                                          
ack +-+-->    C     |                                          
         +----------+                                          
         in-flight heap                                                  

Let's evaluate the in-flight feature.

%%
%% create a queue and enable in-flight feature using time-to-flight (ttf)
{ok, Q} = esq:new("/tmp/q", [{capacity, 10}, {ttf, 5000}]).

%%
%% enqueue multiple messages to queue
[esq:enq(X, Q) || X <- [a, b, c, d, e, f, g, h]].

%%
%% dequeue message and read it's receipt
[#{receipt := Receipt}] = esq:deq(Q).

%%
%% acknowledge the message to queue
esq:ack(Receipt, Q).

%%
%% message becomes visible to consumer again if acknowledgement is not
%% delivered with-in time-to-flight
[#{payload := X}] = esq:deq(Q).

timer:sleep(6000).

[#{payload := X}] = esq:deq(Q).

Queue timers

  • ttl message time-to-live in milliseconds, expired messages are evicted from queue. The eviction process is executed during reads.
  • ttf message time-to-flight in milliseconds, the time required to deliver message acknowledgment before it reappears to client(s) again. If parameter is not defined then in-flight heap is not used and message acknowledgment is not required.
  • tts queue time-to-sync (rotate) file segments in milliseconds. Any enqueue message might remain invisible until sync is performed.

Performance

The queue performance is evaluated using basho benchmark with 25% dequeue and 75% enqueue workload on MacBook Pro, Intel Core i7, 2.8GHz, 16GB 2133 MHz LPDDR3, 256 SSD

Queue performance

How to Contribute

The daemon is Apache 2.0 licensed and accepts contributions via GitHub pull requests:

  • Fork the repository on GitHub
  • Read build instructions
  • Make a pull request

The build process requires Erlang/OTP version 19.0 or later and essential build tools.

Build and run service in your development console. The following command boots Erlang virtual machine and opens Erlang shell.

git clone https://github.com/fogfish/esq
cd esq
make
make run

Now you are able to create queues and debug them.

commit message

The commit message helps us to write a good release note, speed-up review process. The message should address two question what changed and why. The project follows the template defined by chapter Contributing to a Project of Git book.

Short (50 chars or less) summary of changes

More detailed explanatory text, if necessary. Wrap it to about 72 characters or so. In some contexts, the first line is treated as the subject of an email and the rest of the text as the body. The blank line separating the summary from the body is critical (unless you omit the body entirely); tools like rebase can get confused if you run the two together.

Further paragraphs come after blank lines.

Bullet points are okay, too

Typically a hyphen or asterisk is used for the bullet, preceded by a single space, with blank lines in between, but conventions vary here

bugs

If you experience any issues with the library, please let us know via GitHub issues. We appreciate detailed and accurate reports that help us to identity and replicate the issue.

  • Specify the configuration of your environment. Include which operating system you use and the versions of runtime environments.

  • Attach logs, screenshots and exceptions, in possible.

  • Reveal the steps you took to reproduce the problem.

Changelog

The library uses semantic versions to identify stable releases.

  • 1.0.0 - a simplified persistent queue
  • 0.8.5 - a stable release of queue that supports various back-ends

License

Copyright 2013 Dmitry Kolesnikov

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

More Repositories

1

datalog

simplified query engine based on logic programming paradigm
Erlang
139
star
2

cache

Erlang in-memory cache
Erlang
136
star
3

datum

pure functional and generic programming for Erlang
Erlang
119
star
4

aws-cdk-pure

Purely Functional and high-order cloud components with AWS CDK
TypeScript
93
star
5

golem

pure functional and generic programming for Go
Go
46
star
6

typhoon

distributed system stress and load testing tool
Erlang
43
star
7

serverless

Serverless Erlang runtime for AWS Lambda Service
Erlang
29
star
8

csv

csv parser, optimized for performance
Makefile
22
star
9

dynamo

Generic Golang Key/Value trait for AWS storage services
Go
18
star
10

pts

The library provides hashtable-like interface to manipulate data distributed across Erlang processes.
Erlang
15
star
11

hash

collection of hash functions for Erlang applications
Erlang
12
star
12

feta

fogfish erlang toolkit archive
Erlang
10
star
13

node-lambda-typescript-template

The bare minimum for a TypeScript app running on Amazon Lambda.
TypeScript
10
star
14

guid

K-ordered unique identifiers in lock-free and decentralised manner for Golang applications
Go
10
star
15

makefile

Erlang workflow
Makefile
10
star
16

word2vec

Golang "native" implementation of word2vec algorithm (word2vec++ port)
C++
10
star
17

oauth2

oauth2 authorization server
Erlang
9
star
18

ek

Erlang clustering
Erlang
8
star
19

nebula

Erlang nodes discovery agent
Erlang
8
star
20

ddb

AWS Generic Storage Drivers
Erlang
8
star
21

relog

Redis datalog support
Erlang
8
star
22

m_http

A class of Erlang monads which can do http requests
Erlang
7
star
23

gurl

α΅πŸ†„πŸ†πŸ…» is a combinator library for network I/O
Go
6
star
24

blueprint-serverless-golang

AWS CDK template for serverless Golang
Go
6
star
25

hyperion

Erlang Vanilla Node
Erlang
6
star
26

uid

erlang fault tolerant service to generate unique identities
Erlang
6
star
27

svg

Erlang
5
star
28

certbot-on-aws

Serverless integration with https://letsencrypt.org for microservices hosted on AWS
Makefile
5
star
29

schemaorg

Go types of schema.org ontology
Go
5
star
30

semantic

Semantic Web ToolKit for Erlang applications
Erlang
4
star
31

socat

Command line utility to cat files via network socket
Erlang
4
star
32

ring

consistent hashing data structure
Go
4
star
33

elata

Erlang LATency Agent: software solution to gather telemetry of software components (written on erlang)
Shell
4
star
34

swirl

swirl is the Erlang port of whiskers.js template library.
Erlang
4
star
35

streamfs

Append-only file system access with stream abstraction
Erlang
3
star
36

esh

Erlang to Shell binding
Erlang
3
star
37

crdts

Convergent replicated data type for Erlang
Erlang
3
star
38

hnsw

Hierarchical Navigable Small World Graphs
Go
3
star
39

curie

The type CURIE (compact URI) for Golang
Go
3
star
40

erlang-in-docker

Erlang/OTP container
Dockerfile
3
star
41

elasticnt

N-triple intake to Elastic Search
Erlang
3
star
42

chronolog

time series database
Erlang
3
star
43

ecsd

AWS ECS microservice supervisor
Erlang
3
star
44

permit

a high-level api for security tokens management.
Erlang
3
star
45

stdio

Creating streams and performing input and output operations on them
Erlang
3
star
46

s3am

Stream I/O to aws s3 buckets
Erlang
3
star
47

faults

Type safe constructs to annotate Golang errors with the context
Go
3
star
48

gouldian

Go combinator library for building HTTP serverless applications
Go
3
star
49

datomic-aws

AWS Appliance to managed Datomic solutions
Shell
2
star
50

serverless-runtime

Experimental runtime for serverless Erlang application (Use fogfish/serverless) instead
Erlang
2
star
51

swarm

Go channels for distributed queueing and event-driven systems
Go
2
star
52

it

Human-friendly unit tests assertions for Go
Go
2
star
53

code-build-bot

Serverless CI/CD with AWS CodeBuild
TypeScript
2
star
54

aae

active anti-entropy library
Erlang
2
star
55

schemacli

schema.org ontology command-line
Go
2
star
56

d3

direct distributed dets interface
Erlang
2
star
57

tslab

A slab-like allocator library for generic type T
Go
2
star
58

dive

ephemeral and persistent b-tree interface
Erlang
1
star
59

esio

HTTP client to Elastic Search for Erlang application.
Erlang
1
star
60

homebrew-qemu-9pfs

Homebrew Tap install QEMU with 9P filesystem
Ruby
1
star
61

geojson

GeoJSON / RFC7946 codec for Golang
Go
1
star
62

kv8.rel

simple erlang benchmark utility
Shell
1
star
63

elasticlog

Elastic Search datalog support
Erlang
1
star
64

pq

Erlang process queues (pool of workers)
Erlang
1
star
65

znap

Build and replay snapshots from your asynchronous event stream(s)
Scala
1
star
66

ambit

Erlang
1
star
67

cryptex

Semi-automatic cipher for Algebraic Data Types in Golang
Go
1
star
68

erlcc

Erlang Code Compile: wrapper of native compile module
Makefile
1
star
69

tf-workspace

A personal workspace for TensorFlow.
Jupyter Notebook
1
star
70

runscript

tiny wrapper to run script / shell command as root
C
1
star
71

skiplist

Golang SkipList data structure
Go
1
star
72

clue

system and application status repository for Erlang
Erlang
1
star
73

clot

cloud toolkit for Erlang applications
Erlang
1
star
74

hornlog

define and evaluate horn clauses
Makefile
1
star
75

hexer

Hexastore: Sextuple Indexing for Semantic Web Data Management
Go
1
star
76

pns

process namespace
Erlang
1
star
77

go-check-updates

upgrades your go.mod dependencies to the latest versions
Go
1
star
78

stream

Golang file system abstraction tailored for AWS S3, enabling seamless streaming of binary objects along with their corresponding metadata.
Go
1
star