A big, fast and persistent queue based on memory mapped file.

Overview

Big Queue

A big, fast and persistent queue based on memory mapped file.

Notice, bigqueue is just a standalone library, for a high-throughput, persistent, distributed, publish-subscrible messaging system, please refer to Luxun, Luxun messaging system uses bigqueue internally as fast and persistent queue.

##Feature Highlight:

  1. Fast: close to the speed of direct memory access, both enqueue and dequeue are close to O(1) memory access.
  2. Big: the total size of the queue is only limited by the available disk space.
  3. Persistent: all data in the queue is persisted on disk, and is crash resistant.
  4. Reliable: OS will be responsible to presist the produced messages even your process crashes.
  5. Realtime: messages produced by producer threads will be immediately visible to consumer threads.
  6. Memory-efficient: automatic paging & swapping algorithm, only most-recently accessed data is kept in memory.
  7. Thread-safe: multiple threads can concurrently enqueue and dequeue without data corruption.
  8. Simple&Light-weight: current number of source files is 12 and the library jar is less than 30K.

The Big Picture

###Memory Mapped Sliding Window

design

##Performance Highlight:

  • In concurrent producing and consuming case, the average throughput is around 166M bytes per second.
  • In sequential producing then consuming case, the average throughput is around 333M bytes per second.

Suppose the average message size is 1KB, then big queue can concurrently producing and consuming
166K message per second. Basically, the throughput is only limited by disk IO bandwidth.

here is a detailed performance report

##How to Use

  1. Direct jar or source reference
    Download jar from repository mentioned in version history section below, latest stable release is 0.7.0.
    Note : bigqueue depends on log4j, please also added log4j jar reference if you use bigqueue.

  2. Maven reference

     <dependency>
       <groupId>com.leansoft</groupId>
       <artifactId>bigqueue</artifactId>
       <version>0.7.0</version>
     </dependency>
     
     <repository>
       <id>github.release.repo</id>
       <url>https://raw.github.com/bulldog2011/bulldog-repo/master/repo/releases/</url>
     </repository>
    

##Docs

  1. a simple design doc
  2. big queue tutorial
  3. fanout queue tutorial
  4. big array tutorial
  5. how to turn big queue into a thrift based queue service
  6. use case : producing and consuming 4TB log daily on one commodity machine
  7. use case : sort and search 100GB data on a single commodity machine
  8. the architecture and design of a pub-sub messaging system tailored for big data collecting and analytics
  9. a big, fast and persistent queue[ppt]

Version History

0.7.0 - March 24, 2013 : repository

  • Feature: support fanout queue semantics
  • Enhancement: make data file size configurable

0.6.1 — January 29, 2013 : repository

  • Initial version:)

##Copyright and License Copyright 2012 Leansoft Technology [email protected]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or 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.

Comments
  • OutOfMemory Exception

    OutOfMemory Exception

    Hi, I am currently using bigqueue in one of our projects. For many "queues" i am getting a "Map Failed" because of OutOfMemory Now. The data i am trying to queue isnt huge. It is not greater than a few Kbs at the max. My machine has at least A gig of RAM free and disk space is not filled up as well. It is however a windows 7 machine (64 bit). Any clues to what might be causing this. Following is the snippet of the relevant portions of the stacktrace:

    java.io.IOException: Map failed at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:748) at com.leansoft.bigqueue.page.MappedPageFactoryImpl.acquirePage(MappedPageFactoryImpl.java:86) at com.leansoft.bigqueue.BigArrayImpl.append(BigArrayImpl.java:325) at com.leansoft.bigqueue.BigQueueImpl.enqueue(BigQueueImpl.java:92) ... Caused by: java.lang.OutOfMemoryError: Map failed at sun.nio.ch.FileChannelImpl.map0(Native Method) at sun.nio.ch.FileChannelImpl.map(FileChannelImpl.java:745) ... 36 more

    opened by anubhavsahoo 3
  • Adding support for non-blocking wait

    Adding support for non-blocking wait

    It would be nice to have a possibility to use something like Java Future to wait for new items in the queue. By making use of the ListenableFuture interested objects could be informed whenever new items are enqueued.

    I'd like to implement this feature as pull request if it's appreciated.

    opened by TobiasMende 2
  • Support of iteration over items in queue

    Support of iteration over items in queue

    This feature can be useful to log items in a queue or apply any other actions over the items

    • [x] interface ItemIterator added
    • [x] applyForEach(ItemIterator iterator) method added
    • [x] tests added (simple and concurrent)

    Please check an implementation of applyForEach in BigQueueImpl

    opened by illya13 2
  • OutOfMemoryError while adding/removing items

    OutOfMemoryError while adding/removing items

    Hello!

    Hope you are doing well. I recently found you project and decided to play around. I built a really simple test:

    IBigQueue bigQueue = new BigQueueImpl("bigqueue", "demo");

        final String sampleData = "sdfsad hfbsfbjhsdabfha sfbsabfjhns fnhsba jbfsajdb flasb kf" +
                "sfmk basn,kbfjas dbhfsd bfs jbsadfg sahg fjhkas gfhjkasb kjhasbf askhk skajdbgfshggasa mkgnkasg jksa" +
                "js adhf ljashdjfhsajdk hfsadjh fjisahg fiusd hiusdfg ashjsa hfjkafsgasbhb gfjksagjsa gkj sag" +
                "s akjfglsahijusaf hijlsahg iujsalsailkj sagkls jghasjkg asglj" +
                "sa jkghlash gjlsahg jlksah dgj sahgjhs jghbsjka gfkjs jsa jksadghjkasghkj ashgfkjas hkjsaghjksa h" +
                " sajgbljsag jksa;aposg hijsbgji sah soag ghhas;og asi; gwir g;osagjksa hgewah 'pwaj gas" +
                " husgh ousa hgas gho;usahg o;ash fo;asgosagjh askgb ojuias ohgaho iusahgajui sghha;s g" +
                "a sjiughuoashg douisah guilsahg ouisahdg ouisa goiuash gh;oas dhghj;sh l sadgh";
    
        final long start = System.currentTimeMillis();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(out);
        for (int i = 0; i < 10000000; i++) {
            oos.writeObject(sampleData + i);
            bigQueue.enqueue(out.toByteArray());
            out.reset();
        }
    
        long middle = System.currentTimeMillis();
        System.out.println((System.currentTimeMillis() - start ) / 1000);
    
        while (bigQueue.size() > 0) {
            bigQueue.dequeue();
        }
    
        System.out.println(((System.currentTimeMillis() - middle) / 1000));
        bigQueue.gc();
    

    and it results in Exception in thread "main" java.lang.OutOfMemoryError: GC overhead limit exceeded at com.leansoft.bigqueue.page.MappedPageFactoryImpl.acquirePage(MappedPageFactoryImpl.java:105) at com.leansoft.bigqueue.BigArrayImpl.append(BigArrayImpl.java:323) at com.leansoft.bigqueue.BigQueueImpl.enqueue(BigQueueImpl.java:79) at com.queue.App.main(App.java:91) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)

    opened by afilipchik 2
  • It takes a long time to delete the file.

    It takes a long time to delete the file.

    [2015-03-24 13:11:46.882] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/index/page-119.dat was just deleted. 23ms
    [2015-03-24 13:11:46.894] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/index/page-119.dat was just deleted. 38ms
    [2015-03-24 13:11:46.928] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2053.dat was just deleted. 70ms
    [2015-03-24 13:11:46.932] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2052.dat was just deleted. 74ms
    [2015-03-24 13:11:46.958] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2055.dat was just deleted. 98ms
    [2015-03-24 13:11:46.958] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2051.dat was just deleted. 99ms
    [2015-03-24 13:11:46.965] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2052.dat was just deleted. 106ms
    [2015-03-24 13:11:46.966] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2054.dat was just deleted. 108ms
    [2015-03-24 13:11:46.971] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2057.dat was just deleted. 111ms
    [2015-03-24 13:11:46.980] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2056.dat was just deleted. 115ms
    [2015-03-24 13:11:46.988] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2058.dat was just deleted. 128ms
    [2015-03-24 13:11:46.990] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2057.dat was just deleted. 125ms
    [2015-03-24 13:11:47.022] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2056.dat was just deleted. 162ms
    [2015-03-24 13:11:47.023] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2058.dat was just deleted. 98ms
    [2015-03-24 13:11:47.028] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2054.dat was just deleted. 168ms
    [2015-03-24 13:11:47.039] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2059.dat was just deleted. 169ms
    [2015-03-24 13:11:47.040] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2059.dat was just deleted. 179ms
    [2015-03-24 13:11:47.040] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/explorer-kafka/tiara_weblog/data/page-2053.dat was just deleted. 181ms
    [2015-03-24 13:11:47.043] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2051.dat was just deleted. 185ms
    [2015-03-24 13:11:47.044] INFO  c.l.b.p.MappedPageFactoryImpl - Page file /daum/logs/tiara/tiara-log-kafka/tiara_weblog/data/page-2055.dat was just deleted. 186ms
    
    opened by thinker0 0
  • MappedByteBuffer not release due to JDK11 does not support sun.misc.Cleaner

    MappedByteBuffer not release due to JDK11 does not support sun.misc.Cleaner

    Hi,

    MappedPageImpl current using sun.misc.Cleaner to clean up the mapped byte buffer of the index/data page files.

    class sun.misc.Cleaner doest not exist in JDK11, for those app run on JDK11 will have issue on disk release.

    with Ubuntu 18/OpenJDK11, use below command you can see the deleted files, and there didn't didn't release, until restart the app.

    lsof -p | grep DEL

    use htop command will see the process with high VIRT (run to 100G+)

    There have sun.misc.Unsafe.invokeCleaner(java.nio.ByteBuffer directBuffer) available able to resolve that issue.

    patch.diff.tar.gz

    opened by 0tanks 2
  • How to clear consumed items in order to reduce data on disk ?

    How to clear consumed items in order to reduce data on disk ?

    I create a bigqueue, and enqueue many items, then dequeue all. But the size of bigqueue on disk will become bigger and bigger.

            String queueDir = "/Users/ym/data/bigqueue";
            String queueName = "demo";
            IBigQueue bigQueue = null;
            try {
                bigQueue = new BigQueueImpl(queueDir, queueName);
    
    
                for (int i = 0; i < 1000000; i++) {
                    String item = String.valueOf(i);
                    bigQueue.enqueue(item.getBytes());
                }
    
                // dequeue some items
                for (int i = 0; i < 1000000; i++) {
                    String item = new String(bigQueue.dequeue());
                    System.out.println(item);
                }
            } finally {
                bigQueue.close();
            }
    

    How to release space or reduce file ?

    I have tried IBigQueue.gc() , but not working . IBigQueue.removeAll() will reduce the file, but I only want to clear consumed items.

    opened by yanggeorge 1
  • Golang version to supports bigqueue

    Golang version to supports bigqueue

    We use serval program language in our team, except java also use golang. so we develop golang version to support bigqueue which storage file full compatiable with Java. now we open it on github. Any questions could visit https://github.com/jhunters/bigqueue

    opened by jhunters 1
A lightning fast, transactional, file-based FIFO for Android and Java.

Tape by Square, Inc. Tape is a collection of queue-related classes for Android and Java. QueueFile is a lightning-fast, transactional, file-based FIFO

Square 2.4k Dec 30, 2022
Worker-queue implementation on top of Java and database

Database Queue Library provides worker-queue implementation on top of Java and database. Fintech company YooMoney uses db-queue in cases where reliabi

null 17 Dec 12, 2022
A Persistent Java Collections Library

PCollections A Persistent Java Collections Library Overview PCollections serves as a persistent and immutable analogue of the Java Collections Framewo

harold cooper 708 Dec 28, 2022
Estrutura de dados queue, filas.

Estrutura_de_dados_queue Estrutura de dados queue, filas. – estrutura de dados linear em que a inserção e a remoção de elementos de uma sequência se f

Marcus Vinícius Ribeiro Andrade 2 Dec 12, 2021
A FlinkSQL studio and real-time computing platform based on Apache Flink

Dinky 简介 实时即未来,Dinky 为 Apache Flink 而生,让 Flink SQL 纵享丝滑,并致力于实时计算平台建设。 Dinky 架构于 Apache Flink,增强 Flink 的应用与体验,探索流式数仓。即站在巨人肩膀上创新与实践,Dinky 在未来批流一体的发展趋势下潜

null 1.5k Dec 30, 2022
Facebook Clone created using java based on Graph data Structure

Facebook Clone Facebook Clone created using java based on Graph data Structure Representation of Social Media using Graph Data Structure in Java It is

yogita pandurang chaudhari 1 Jan 16, 2022
gRPC and protocol buffers for Android, Kotlin, and Java.

Wire “A man got to have a code!” - Omar Little See the project website for documentation and APIs. As our teams and programs grow, the variety and vol

Square 3.9k Dec 23, 2022
This repository contains codes for various data structures and algorithms in C, C++, Java, Python, C#, Go, JavaScript and Kotlin.

Overview The goal of this project is to have codes for various data structures and algorithms - in C, C++, Java, Python, C#, Go, JavaScript and Kotlin

Manan 25 Mar 2, 2022
This repository contains all the Data Structures and Algorithms concepts and their implementation in several ways

An Open-Source repository that contains all the Data Structures and Algorithms concepts and their implementation in several ways, programming questions and Interview questions. The main aim of this repository is to help students who are learning Data Structures and Algorithms or preparing for an interview.

Pranay Gupta 691 Dec 31, 2022
Union, intersection, and set cardinality in loglog space

HyperMinHash-java A Java implementation of the HyperMinHash algorithm, presented by Yu and Weber. HyperMinHash allows approximating set unions, inters

LiveRamp 48 Sep 22, 2022
Popular Algorithms and Data Structures implemented in popular languages

Algos Community (college) maintained list of Algorithms and Data Structures implementations. Implemented Algorithms Algorithm C CPP Java Python Golang

IIIT Vadodara Open Source 1k Dec 28, 2022
A repository that contains Data Structure and Algorithms coded on Java

A repository that contains Data Structure and Algorithms coded on Java . It will also contain solutions of questions from Leetcode.

Akshat Gupta 6 Oct 15, 2022
Flink Table Store is a unified streaming and batch store for building dynamic tables on Apache Flink

Flink Table Store is a unified streaming and batch store for building dynamic tables on Apache Flink

The Apache Software Foundation 366 Jan 1, 2023
🎓☕ Repository of lessons and exercises from loiane.training's course on data structure with Java

☕ Curso estrutura de dados com Java by @loiane.training Repositório com as aulas e exercícios do curso de estrutura de dados com Java da loiane.traini

Leticia Campos 2 Feb 1, 2022
Algorithm and Data Structrue

SWE241P Algorithm and Data Structure Ex1 TreeSet with Red-Black Tree HashSet LinkedList Set Ex 2 Selection Sort Insertion Sort Heap Sort Merge Sort Qu

Tiger Liu 4 Apr 13, 2022
Data structures and algorithms exercises in java

Data structure and algorithms in Java About The Project [] In this repository you can find examples of data structure exercises solved in java and som

Luis Perez Contreras 1 Nov 25, 2021
Data structures & algorithms implemented in Java and solutions to leetcode problems.

Hello, World! ?? Hey everyone, I'm Sharad ☃ , and I'm a Software Engineer ?? at eGain! This repository ?? is all about data structures & algorithms an

Sharad Dutta 16 Dec 16, 2022
A fast, simple persistent queue written in Java

Ladder Introduction Ladder is a lightning fast persistent queue written in Java. Usage Installation // TODO publish to Maven Central Create persistent

null 6 Sep 9, 2022
Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository containing all my study material.

Jornada Big Tech (Big Tech Journey) Jornada Big Tech: I will have 3 months to study and prepare myself for the Big Tech interviews. Repository contain

Camila Maia 87 Dec 8, 2022
Persistent priority queue over sql

queue-over-sql This projects implement a persistent priority queue (or a worker queue) (like SQS, RabbitMQ and others) over sql. Why? There are some c

Shimon Magal 13 Aug 15, 2022