Concurrent Message Service M. Clemencic CERN - LHCb Forum on - - PowerPoint PPT Presentation

concurrent message service
SMART_READER_LITE
LIVE PREVIEW

Concurrent Message Service M. Clemencic CERN - LHCb Forum on - - PowerPoint PPT Presentation

Concurrent Message Service M. Clemencic CERN - LHCb Forum on Concurrent Programming Models and Frameworks 24-10-2012 M. Clemencic (CERN - LHCb) Concurrent Message Service 24-10-2012 1 / 11 Outline Introduction 1 Gaudi Concurrent


slide-1
SLIDE 1

Concurrent Message Service

  • M. Clemencic

CERN - LHCb

Forum on Concurrent Programming Models and Frameworks 24-10-2012

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 1 / 11

slide-2
SLIDE 2

Outline

1

Introduction

2

Gaudi Concurrent Message Service

3

Considerations and Summary

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 2 / 11

slide-3
SLIDE 3

Introduction

Outline

1

Introduction

2

Gaudi Concurrent Message Service

3

Considerations and Summary

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 3 / 11

slide-4
SLIDE 4

Introduction

The problem

Applications need logging tools

Gaudi uses the class MessageSvc

Logging must be concurrency-friendly

concurrent message pushing sequential message handling preserve order avoid bottlenecks

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 4 / 11

slide-5
SLIDE 5

Gaudi Concurrent Message Service

Outline

1

Introduction

2

Gaudi Concurrent Message Service

3

Considerations and Summary

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 5 / 11

slide-6
SLIDE 6

Gaudi Concurrent Message Service

Requirements

Drop-in replacement

message reporting is performed by only one method

Concurrent input / sequential output

central message queue

Avoid interference with Algorithms/Modules execution

deferred reporting execution in another thread

Lock-free implementation

use existing concurrency libraries/tools

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 6 / 11

slide-7
SLIDE 7

Gaudi Concurrent Message Service

Requirements

Drop-in replacement

message reporting is performed by only one method

Concurrent input / sequential output

central message queue

Avoid interference with Algorithms/Modules execution

deferred reporting execution in another thread

Lock-free implementation

use existing concurrency libraries/tools

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 6 / 11

slide-8
SLIDE 8

Gaudi Concurrent Message Service

Requirements

Drop-in replacement

message reporting is performed by only one method

Concurrent input / sequential output

central message queue

Avoid interference with Algorithms/Modules execution

deferred reporting execution in another thread

Lock-free implementation

use existing concurrency libraries/tools

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 6 / 11

slide-9
SLIDE 9

Gaudi Concurrent Message Service

Requirements

Drop-in replacement

message reporting is performed by only one method

Concurrent input / sequential output

central message queue

Avoid interference with Algorithms/Modules execution

deferred reporting execution in another thread

Lock-free implementation

use existing concurrency libraries/tools

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 6 / 11

slide-10
SLIDE 10

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-11
SLIDE 11

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-12
SLIDE 12

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Algorithm’s first message.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-13
SLIDE 13

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Algorithm’s second message.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-14
SLIDE 14

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Queue is free: schedule new task.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-15
SLIDE 15

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Report task started.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-16
SLIDE 16

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Queue is busy: just append.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-17
SLIDE 17

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Report task completed: schedule new task.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-18
SLIDE 18

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Report task may start before the previous one returned.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-19
SLIDE 19

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

The destructor of SerialTaskQueue is blocking.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-20
SLIDE 20

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Report task completed: stop waiting.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-21
SLIDE 21

Gaudi Concurrent Message Service

Implementation

Using Intel R

TBB & C++11

std::atomic tbb::concurrent_queue tbb::task tbb::task::enqueue

Generic SerialTaskQueue

from TBB pattern Local Serializer

Delete may complete before the task returns.

: Algorithm : MessageSvc : SerialTaskQueue : TBB new message1 add() task::enqueue message2 add() completed task::enqueue report() Processing Processing delete wait completed report() destroyed

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 7 / 11

slide-22
SLIDE 22

Considerations and Summary

Outline

1

Introduction

2

Gaudi Concurrent Message Service

3

Considerations and Summary

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 8 / 11

slide-23
SLIDE 23

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-24
SLIDE 24

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-25
SLIDE 25

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-26
SLIDE 26

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-27
SLIDE 27

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-28
SLIDE 28

Considerations and Summary

Considerations (1/2)

SerialTaskQueue is relatively simple and lightweight

can be used for other complex tasks

Concept available in libdispatch

not tried yet

enqueue vs. spawn vs. continuation

continuation → run immediately in the same thread spawn → run ASAP , better if in the same thread enqueue → run later, when you have time

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 9 / 11

slide-29
SLIDE 29

Considerations and Summary

Considerations (2/2)

Tasks should not be less than ∼10,000 clock cycles

∼100,000 clock cycles for some parallel loops see TBB manual

I/O ops. may use a dedicated thread outside the TBB scheduler

see QuickThread Programming (non-free) vs. TBB

Non-TBB applications could already use the new class

use a spare thread for messaging keep the main thread busy

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 10 / 11

slide-30
SLIDE 30

Considerations and Summary

Considerations (2/2)

Tasks should not be less than ∼10,000 clock cycles

∼100,000 clock cycles for some parallel loops see TBB manual

I/O ops. may use a dedicated thread outside the TBB scheduler

see QuickThread Programming (non-free) vs. TBB

Non-TBB applications could already use the new class

use a spare thread for messaging keep the main thread busy

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 10 / 11

slide-31
SLIDE 31

Considerations and Summary

Considerations (2/2)

Tasks should not be less than ∼10,000 clock cycles

∼100,000 clock cycles for some parallel loops see TBB manual

I/O ops. may use a dedicated thread outside the TBB scheduler

see QuickThread Programming (non-free) vs. TBB

Non-TBB applications could already use the new class

use a spare thread for messaging keep the main thread busy

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 10 / 11

slide-32
SLIDE 32

Considerations and Summary

Summary

Even if not in TBB, a serial queue is easy to write. The enqueue approach fits better deferred work. To-Do list:

measure the effect of deferred messaging try different approaches (grouping of messages, extra thread, . . . ) evaluate possible use in current single-thread applications

  • M. Clemencic (CERN - LHCb)

Concurrent Message Service 24-10-2012 11 / 11