Socket
Socket
Sign inDemoInstall

github.com/SamuelTissot/bqueue

Package Overview
Dependencies
3
Alerts
File Explorer

Install Socket

Detect and block malicious and high-risk dependencies

Install

    github.com/SamuelTissot/bqueue

Package bqueue is a "in memory" queue. it Collects jobs via the `CollectJob` func who takes a interface `Job`


Version published

Readme

Source

BQUEUE

Build Status
branchstatus
masterCircleCI

A buffered async queue

Based on Marcio Castilho article “Handling 1 Million Requests per Minute with Go”

Why

We needed a simple and quick queue system. to handle request rapidely without impacting performance. Each of our job could take up to 20s to execute.

How it works

by using the awesomeness of channels

Channels are the pipes that connect concurrent goroutines. You can send values into channels from one goroutine and receive those values into another goroutine

With channels we are able to flow the data between states without any performance impact

  ┌─────────────────────────────────┐                             ┌───────────────────────────────┐
  │Queue                            │                             │Worker                         │
  │---                              │                             │---                            │
  │    maxWorker   int              │                             │    ID          int            │
  │    JobRequests chan chan Job    │                             │    JobHunting  chan Job       │
  │    JobReceived chan Job         │                             │    jobRequests chan chan Job  │
  │                                 │                             │    QuitChan    chan bool      │
  │                                 │                             │                               │
  │M: Start()                       │                             │                               │
  │-                                │                             │                               │
  │Also initialize the workers      │     ┌────────────────┐      │                               │
  │and channels                     │     │ share the same │      │M: Start() |  goroutine        │
  │                                 │     │    instance    │      │-                              │
  │                                 │     ├────────────────┤  ┌──▶│Receive a job from JobRequests │
  │M: CollectJob(j Job)             │     │JobRequests     │  │   │Calls do passing the job       │
  │-                                │┌───▶│---             │──┘   │                               │
  │adds the job to the JobReceived  ││    │(chan chan Job) │      │                               │
  │                                 ││    └────────────────┘      │                               │
  │                                 ││                            │M: do(j Job)                   │
  │M: dispatch() | goroutine      ──┼┘                            │-                              │
  │-                                │                             │process the job                │
  │Looks for job in JobReceived     │                             │                               │
  │Then add it to the JobRequests   │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  └─────────────────────────────────┘                             └───────────────────────────────┘

FAQs

Last updated on 10 Jun 2019

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc