Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ bqueue Public
forked from SamuelTissot/bqueue

A buffer async queue

License

stevenh/bqueue

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BQUEUE

Build Status
branch status
master CircleCI

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   │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  │                                 │                             │                               │
  └─────────────────────────────────┘                             └───────────────────────────────┘

About

A buffer async queue

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%