virtual queues as a trade processing pattern n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Virtual Queues as a Trade Processing Pattern PowerPoint Presentation
Download Presentation
Virtual Queues as a Trade Processing Pattern

Loading in 2 Seconds...

play fullscreen
1 / 55

Virtual Queues as a Trade Processing Pattern - PowerPoint PPT Presentation


  • 59 Views
  • Uploaded on

Virtual Queues as a Trade Processing Pattern. Uri Cohen @uri1803 | github.com /uric Head of Product @ GigaSpaces. Event Processing at Massive Scale Approaches to Concurrency . Uri Cohen @uri1803 | github.com /uric Head of Product @ GigaSpaces. This is What It Used to Be Like.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Virtual Queues as a Trade Processing Pattern' - jabari


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
virtual queues as a trade processing pattern

Virtual Queues as a Trade Processing Pattern

Uri Cohen

@uri1803 | github.com/uric

Head of Product @ GigaSpaces

event processing at massive scale approaches to concurrency

Event Processing at Massive Scale Approaches to Concurrency

Uri Cohen

@uri1803 | github.com/uric

Head of Product @ GigaSpaces

some numbers

15 Billion Trades / Day on NYSE alone

Some Numbers

http://www.nytimes.com/2011/08/27/business/as-trade-volumes-soar-exchanges-cash-in.html

some numbers1

That’s

641K

Trades / Second

Some Numbers

http://www.nytimes.com/2011/08/27/business/as-trade-volumes-soar-exchanges-cash-in.html

some numbers2

12 Billion

Shares change hands every day

Some Numbers

http://www.bloomberg.com/news/2012-01-23/stock-trading-is-lowest-in-u-s-since-2008.html

some numbers3

$4 Million The cost of 1 millisecond of latency to a broker

Some Numbers

http://www.tabbgroup.com/PublicationDetail.aspx?PublicationID=346

the problem

Massive stream of events

Time is money, literally

Can’t lose a single message

Fairness is a must

The Problem

what it really means

Low latencyIn memory, GC tuning

Scalability Multi-core Multi-node

Ordering By price, order time

Exclusivity

Resiliency

What it Really Means

trading is just one use case

All things FCFS, with a limited stock

Flight booking

Betting

Online Auctions

Cloud Spot Instances

eCommerce

Trading is Just One Use Case

queue seda actor style
Queue (SEDA/Actor Style)

Not Validated

Validated

Processed

Validator

Processor

queue seda actor style1

The Good: Ordered (Is it fair?) Multi-threaded

The Bad: Not very scalable Locking Context switching Transient

Queue (SEDA /Actor Style)

the cost of locking

The Cost of Locking

http://disruptor.googlecode.com/files/Disruptor-1.0.pdf

queue lack of fairness
Queue (Lack of) Fairness

50

60

Consumer Thread 1

Consumer Thread 2

queue lack of fairness1
Queue (Lack of) Fairness

50

60

Consumer Thread 1

Consumer Thread 2

queue lack of fairness2
Queue (Lack of) Fairness

Can you tell which order will be executed 1st?

50

60

Consumer Thread 1

Consumer Thread 2

single threaded queue
Single-Threaded Queue

Validator

Processor

single threaded queue1

The Good: Fast, very fastNo contention No context switches Always fair

The Bad: Multi-core? Not fit for Intense compute & I/ONeed to be async. Transient

Single- Threaded Queue

segmented queue
Segmented Queue

Processor thread pool per segment

Symbol=A-H

Symbol=I-S

Symbol=T-Z

Validator

Processor

Processor

segmented queue optimization
Segmented Queue - Optimization

Single Processor thread pool, pick random segment

Symbol=A-H

Symbol=I-S

Symbol=T-Z

Processor

segmented queue1

The Good: ScalableBut segments can get hot Minimizes contention

The Bad: Not trivial to implement Still unfairIs total ordering needed? Transient

Segmented Queue

implicit exclusivity
Implicit Exclusivity

Single processor thread per segment

Symbol=A-H

Symbol=I-S

Symbol=T-Z

Processor

Processor

Processor

explicit exclusivity
Explicit Exclusivity

Shared thread pool, mark segments under processing (CAS)

Segment 1

Segment 2

Segment 3

Processor

explicit exclusivity1
Explicit Exclusivity

Shared thread pool, mark segments under processing (CAS)

Segment 1

Segment 2

Segment 3

Processor

explicit exclusivity2
Explicit Exclusivity

Shared thread pool, mark segments under processing (CAS)

Segment 1

Segment 2

Segment 3

Processor

explicit exclusivity3
Explicit Exclusivity

Shared thread pool, mark segments under processing (CAS)

Segment 1

Segment 2

Segment 3

Processor

dynamic segmentation
Dynamic Segmentation

Segments are created and removed as needed

Processor

dynamic segmentation1
Dynamic Segmentation

Segments are created and removed as needed

“GOOG”

Processor

dynamic segmentation2
Dynamic Segmentation

Segments are created and removed as needed

“GOOG”

Processor

dynamic segmentation3
Dynamic Segmentation

Segments are created and removed as needed

“GOOG”

“AAPL”

Processor

dynamic segmentation4
Dynamic Segmentation

Segments are created and removed as needed

“AMZN”

“GOOG”

“AAPL”

Processor

dynamic segmentation5

Segments created as needed

Randomize on segments until available one found

Fast, scalable, fair

We call it “FIFO groups” or “Virtual Queues”

Dynamic Segmentation

it can and does get much more complex

Memory state can get corrupt on errors

It’s not always as simple as “pop off the queue” limits, priorities, circuit breakers, etc.

Resiliency is always a pain

It Can (and Does) Get Much More Complex

a bit about usability

What you don’t want to do

Implement data structures Handle concurrency Handle HA Handle transactions

A Bit about Usability

a bit about usability1

What you want to control

Event flow Grouping attribute (e.g symbol) Event handlers

A Bit about Usability

data grid as a foundation

Transactional

Highly available

Supports complex matching

Data Grid as a Foundation

thank you
Thank You!

References:

http://martinfowler.com/articles/lmax.html

http://www.nytimes.com/2011/08/27/business/as-trade-volumes-soar-exchanges-cash-in.html

http://disruptor.googlecode.com/files/Disruptor-1.0.pdf

http://www.gigaspaces.com/wiki/display/XAP9/FIFO+Grouping