Scaling NServiceBus NSBCon NY by Jimmy Bogard

33
Scaling NServiceBus Jimmy Bogard @jbogard github.com/jbogard jimmybogard.lostechies.com

description

The Daily AS/400 Dump Processing bulk data

Transcript of Scaling NServiceBus NSBCon NY by Jimmy Bogard

Page 1: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Scaling NServiceBus

Jimmy Bogard

@jbogard

github.com/jbogard

jimmybogard.lostechies.com

Page 2: Scaling NServiceBus NSBCon NY by Jimmy Bogard

The Daily AS/400 DumpProcessing bulk data

Page 3: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Characteristics

• 1/day dump of entire SKU catalog

• Flat file

• 1.4M rows daily and growing

• Fill in details for support website

Page 4: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Consuming Files

DataDBImporter Deadloc

k

Rollback

What made it through?

Page 5: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Consuming Files

Data

Processor

Parser

DB

Commit

Commit

1. Process File2. Process Line

Page 6: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Streaming Bulk Copy

Page 7: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Streaming Bulk Copy

Page 8: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Data Warehouse ExportsExporting Bulk Data

Page 9: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Producing Files

Id Name Changed

1 Walter Y

2 Cora N

3 Alejandro N

4 Carlton Y

5 Janice N

Id Name Changed

1 Walter Y

2 Cora N

3 Alejandro N

4 Carlton Y

5 Janice N

FileExporter

SELECT NameWHERE Changed = ‘Y’

Id Name Changed

1 Walter Y

2 Kiera Y

3 Alejandro N

4 Carlton Y

5 Janice N

UPDATE PeopleSET Changed = ‘N’

We’re missing a change

Page 10: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Producing Files

Id Name BatchId

1 Walter NULL

2 Cora 1

3 Alejandro 1

4 Carlton NULL

5 Janice 2

FileExporter

UPDATE PeopleSET BatchId = 3WHERE BatchId IS NULL

Id Name BatchId

1 Walter 3

2 Cora 1

3 Alejandro 1

4 Carlton 3

5 Janice 2

SELECT Id, NameFROM PeopleWHERE BatchId = 3

Id Name BatchId

1 Walter 3

2 Kiera NULL

3 Alejandro 1

4 Carlton 3

5 Janice 2

1. Mark records to export2. Export marked records

Page 11: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Search Database EnrichmentRouting slips

Page 12: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Characteristics

• Enriching search data from various sources

• Some sources are required, some not

• Some dependent on previous steps

• Initiated with large batch of initial messages

Page 13: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #1: Observer

Publisher

Saga

Price

Catalog

Content

Options

Saga Creation

Page 14: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #1: Observer

Publisher

Saga

Price

Catalog

Content

Options

Queue Contention

Page 15: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #1: Observer

Publisher

Saga

Price

Catalog

Content

Options

Saga Contention

Price

Catalog

Content

Options

Page 16: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #2: Controller

Publisher

Saga

Price

Catalog

Content

Options

Slooooooow

Page 17: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #2: Controller

Publisher

Saga

Price

Catalog

Content

Options

Complicated and slow

Price

Catalog

Content

Options

Page 18: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Register

1) Place Order

Customer

Drinks Coffee ShakesSandwich

Fries

2) Order Accepted

Order #1

3) Item Completed

4) Order Completed

McDonald’s Sagas

Tray Contention

Page 19: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Register

1) Place Order

Customer

2) Prep Meal

Prep

3) Pack Meal

4) Order Completed

Pack

Subway’s Sagas

Page 20: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Routing SlipHow do we route a message consecutively through a series of processing steps when the sequence of steps is not known at design-time and may vary for each message?

Attach a Routing Slip to each message, specifying the sequence of processing steps. Wrap each component with a special message router that reads the Routing Slip and routes the message to the next component in the list.

Page 21: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Option #3: Routing Slip

Initiator

Price

Catalog

Content

Options

Page 22: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Transaction ProcessingDitching DTC and exactly-once messaging

Page 23: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Characteristics

• Processing daily sales transactions for loyalty reward system

• Highly cyclical load

• Longest observed finish time – 10 hours

• New load 4-5X larger on a daily basis

Page 24: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Measuring performance

• Current rate: 5 msgs/sec

• Target rate: 80-90 msgs/sec

• Measured max: 18 msgs/sec

Page 25: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Hardware Upgrade

• SSD All The Things

• Up the cores

• Up the RAM

• Upgrade the network

• Result: doubled throughput

Page 26: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Theoretical maxes

Test Transactions Elapsed Time Throughput

No-op On 75 sec 133/sec

DB On 378 sec 26/sec

DB + Message On 544 sec 18/sec

No-op Off 29 sec 345/sec

DB Off 51 sec 196/sec

DB + Message Off 109 sec 92/sec

Page 27: Scaling NServiceBus NSBCon NY by Jimmy Bogard

2PC in messaging

DB

My Service

2. Save

1. Receive 3. Send

Page 28: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Idempotent handlers

DB

Txn Service

2. Already recorded?3. Record txn

1. Store Txn

Page 29: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Record intent

DB

Txn Service

2. Already recorded?3. Record txn4. Issue coupon

1. Store Txn

Page 30: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Decoupling downstream effects

DB

Coupon Service

1. Find unsent message3. Mark as sent

2. Send

Page 31: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Caveats

• No first-level retries

• No second-level retries

• Pipeline fixes all these things

Page 32: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Result

• 8 hours -> 10 minutes• 180 msgs/sec

Page 33: Scaling NServiceBus NSBCon NY by Jimmy Bogard

Takeaways

• Embrace real-world metaphors

• Optimize when needed, not before

• Tons of material out there

• Clemens Vasters “More features, more cost.”