SlideShare a Scribd company logo
1 of 41
Download to read offline
Dive into SObjectizer-5.5
SObjectizer Team, Jan 2016
Fifth Part: Timers
(at v.5.5.15)
This is the next part of the series of presentations with deep
introduction into features of SObjectizer-5.5.
This part is dedicated to usage of timers. In particular:
● delayed messages;
● periodic messages;
● cancellation of delayed/periodic messages;
● timer thread and timer mechanisms.
SObjectizer Team, Jan 2016
Timers are actively used in typical SObjectizer’s based
applications.
That's why SObjectizer provides easy to use tools for dealing
with timers:
● delayed messages;
● periodic messages.
SObjectizer Team, Jan 2016
A delayed message is delivered after a specified time
interval since the message was sent.
It means that if a delayed message is sent at some time
point T and the delay is 150ms then it will be pushed to
subscribers’ event queues at time point (T+150ms).
SObjectizer Team, Jan 2016
A periodic message is repeatedly delivered after a specified
amount of time.
It means that if a periodic message is sent at some time
point T with delay of 150ms and repetition period of 250ms
then it will be pushed to subscribers’ event queues first time
at time point (T+150ms), then at time point (T+400ms), then
at (T+650ms) and so on.
A periodic message will be repeated until it canceled.
SObjectizer Team, Jan 2016
Delayed Messages
SObjectizer Team, Jan 2016
There are three ways for sending a delayed messages.
The simplest one is to use send_delayed() function.
A reference to SO Environment instance is necessary for
sending a delayed message. That’s why the first argument of
send_delayed() is a reference to environment_t or some
object from which that reference could be obtained.
SObjectizer Team, Jan 2016
Sending a delayed message from ordinary agent:
class my_agent : public so_5::agent_t {
...
virtual void so_evt_start() override {
so_5::send_delayed< some_message >(
so_environment(), // SO Environment to be used.
dest, // Destination mbox.
std::chrono::milliseconds(125), // Delivery delay in ms.
... ); // Arguments to be forwarded to some_message constructor.
}
};
SObjectizer Team, Jan 2016
Sending a delayed message from ad-hoc agent:
env.introduce_coop( []( so_5::coop_t & coop ) {
coop.define_agent().on_start( [&coop] {
so_5::send_delayed< some_message >(
coop.environment(), // SO Environment to be used.
dest, // Destination mbox.
std::chrono::milliseconds(125), // Delivery delay in ms.
... ); // Arguments to be forwarded to some_message constructor.
...
} );
} );
SObjectizer Team, Jan 2016
Function send_delayed can be used to sending a delayed
message to the direct mbox of agent-receiver.
SO Environment in which the receiver is registered will be
used in that case.
SObjectizer Team, Jan 2016
Sending a delayed message to the direct mbox of the agent-
receiver:
class my_agent : public so_5::agent_t {
...
void evt_request( const request & evt ) {
initiate_request_processing( evt );
so_5::send_delayed< check_request >(
*this, // Destination for message.
std::chrono::milliseconds(125), // Delivery delay in ms.
... ); // Arguments to be forwarded to check_request constructor.
}
};
SObjectizer Team, Jan 2016
Function send_delayed() also accepts an ad-hoc agent
proxy:
env.introduce_coop( []( so_5::coop_t & coop ) {
auto a = coop.define_agent();
a.event( a, [a]( const request & evt ) {
initiate_request_processing( evt );
so_5::send_delayed< check_request >(
a, // Destination for message.
std::chrono::milliseconds(125), // Delivery delay in ms.
... ); // Arguments to be forwarded to check_request constructor.
} );
} );
SObjectizer Team, Jan 2016
The second way is to use single_timer() method of
environment_t class:
class my_agent : public so_5::agent_t {
...
void evt_request( const request & evt ) {
initiate_request_processing( evt );
auto delayed_msg = std::make_unique< check_request >( ... );
so_environment().single_timer( std::move(delayed_msg), // Message instance.
so_direct_mbox(), // Destination for message.
std::chrono::milliseconds(125) ); // Delivery delay in ms.
}
};
SObjectizer Team, Jan 2016
Usage of single_timer() is not as easy as usage of
send_delayed().
But single_timer() can be useful if a message instance is
created somewhere else...
SObjectizer Team, Jan 2016
A case where single_timer() can be useful:
class my_agent : public so_5::agent_t {
...
void evt_request( const request & evt ) {
initiate_request_processing( evt );
so_environment().single_timer(
create_check_request_message( evt ), // Message instance.
so_direct_mbox(), // Destination for message.
std::chrono::milliseconds(125) ); // Delivery delay in ms.
}
std::unique_ptr< check_request > create_check_request_message( const request & evt ) {
... // Some complex logic.
return std::make_unique< check_request >( ... );
}
};
SObjectizer Team, Jan 2016
The third way is to use schedule_timer() method of
environment_t class.
Method schedule_timer() returns timer ID which can be used
for timer cancellation.
SObjectizer Team, Jan 2016
An example of delayed message cancellation:
class my_agent : public so_5::agent_t {
so_5::timer_id_t m_check_timer;
...
void evt_request( const request & evt ) {
initiate_request_processing( evt );
m_check_timer = so_environment().schedule_timer(
create_check_request_message( evt ), // Message instance.
so_direct_mbox(), // Destination for message.
std::chrono::milliseconds(125), // Delivery delay in ms.
std::chrono::milliseconds::zero() ); // No repetition.
}
void evt_request_processed() {
// There is no need for delayed message anymore.
m_check_timer.release(); // Cancellation of delivery.
...
}
std::unique_ptr< check_request > create_check_request_message( const request & evt ) { ... }
};
SObjectizer Team, Jan 2016
Periodic Messages
SObjectizer Team, Jan 2016
Periodic message are repeated again and again until it will
be cancelled.
The same message instance is delivered every time. It
means that message instance is not deallocated after
processing. Deallocation will occur when message will be
cancelled.
SObjectizer Team, Jan 2016
There are two ways for sending a periodic message.
The simplest one is to use send_periodic() function.
As for delayed messages the access to SO Environment is
necessary for sending a periodic message. That’s why the
first argument of send_periodic() must be a reference to
environment_t or some object from which that reference
could be obtained.
SObjectizer Team, Jan 2016
Sending of a periodic message from ordinary agent:
class my_agent : public so_5::agent_t {
so_5::timer_id_t m_status_timer;
...
virtual void so_evt_start() override {
m_status_timer = so_5::send_periodic< update_status >(
so_environment(), // SO Environment to be used.
dest, // Destination mbox.
std::chrono::milliseconds(125), // First delivery delay in ms.
std::chrono::milliseconds(250), // Repetition period in ms.
... ); // Arguments to be forwarded to update_status constructor.
}
};
SObjectizer Team, Jan 2016
Function send_periodic() can send a message to the direct
mbox of the agent-receiver:
class my_agent : public so_5::agent_t {
so_5::timer_id_t m_status_timer;
...
virtual void so_evt_start() override {
m_status_timer = so_5::send_periodic< update_status >(
*this, // Destination. SO Environment of target agent will be used.
std::chrono::milliseconds(125), // First delivery delay in ms.
std::chrono::milliseconds(250), // Repetition period in ms.
... ); // Arguments to be forwarded to update_status constructor.
}
};
SObjectizer Team, Jan 2016
The second way is to use schedule_timer() method of
environment_t class:
class my_agent : public so_5::agent_t {
so_5::timer_id_t m_status_timer;
...
virtual void so_evt_start() override {
m_status_timer = so_environment().schedule_timer(
create_status_message(), // Message to be sent periodically.
so_direct_mbox(), // Destination.
std::chrono::milliseconds(125), // First delivery delay in ms.
std::chrono::milliseconds(250) ); // Repetition period in ms.
}
std::unique_ptr< update_status > create_status_message() { ... }
};
SObjectizer Team, Jan 2016
The most important moment in periodic messages sending ‒
is storing the result value of send_periodic() and
schedule_timer().
If the result value is not saved then periodic message will be
cancelled immediately.
This is because the destructor of timer_id_t does timer
cancellation.
SObjectizer Team, Jan 2016
The so_5::timer_id_t class works like a smart pointer.
Destruction of the last timer_id_t pointed to a timer will
destroy the timer and periodic (or delayed) message will be
cancelled.
That’s why at least one timer_id_t object for periodic
message must exist while message delivery is necessary.
SObjectizer Team, Jan 2016
Delayed/Periodic Messages Cancellation
SObjectizer Team, Jan 2016
There are three ways of delayed/periodic messages
cancellation.
All of them use timer_id_t objects. It means that cancellation
is only possible for messages sent via send_periodic() or
schedule_timer().
SObjectizer Team, Jan 2016
The first way is to call release() method of timer_id_t class.
auto id = so_5::send_periodic< Msg >(...);
...
id.release(); // Delivery canceled.
Please note that explicit call of release() method cancels a message
regardless of count of remaining timer_id_t objects pointed to that
timer.
SObjectizer Team, Jan 2016
The second way is destruction of all timer_id_t objects
pointing to the same timer.
If release() method is not called explicitly it will be called in the
destructor of the last timer_id_t object pointing to a timer. This way is
often used in ordinary agents:
class request_processor : public so_5::agent_t {
so_5::timer_id_t m_check_request;
...
void evt_request( const request & evt ) {
m_check_request = so_5::send_periodic< check_request >(
*this, ...); // Timer will be cancelled automatically in
// the destructor of request_processor.
...
}
};
SObjectizer Team, Jan 2016
The third way is assignment of new value to timer_id_t
object.
If this object was the last timer_id_t pointed to a timer then the timer
will be destroyed and message will be cancelled:
auto id = so_5::send_periodic< Msg >(...);
... // Some actions.
id = so_5::send_periodic< Sig >(...); // Cancellation of Msg.
SObjectizer Team, Jan 2016
There is a trick moment with cancellation of delayed
messages...
Delayed message will be cancelled only if it is still under control
of timer thread. If message already leaved timer thread and is
waiting in event queues of recipients then message delivery will
not be cancelled and message will be processed by
subscribers.
For example if delay was 125ms and cancelaction is initiated after
125ms after call to send_delayed there is a high probability that
message will be delivered anyway.
SObjectizer Team, Jan 2016
Timer Thread
SObjectizer Team, Jan 2016
SO Environment starts a special thread for handling timers.
This thread is known as timer thread.
All timers are controlled and processed by that timer thread.
Timer thread can efficiently process big amount of timers:
tens and hundreds of millions. Even billions of timers.
A user can choose a timer mechanism most appropriate for
application needs.
SObjectizer Team, Jan 2016
Three timer mechanisms are supported. Each has its
strengths and weakness:
● timer_wheel
● timer_list
● timer_heap
SObjectizer Team, Jan 2016
timer_wheel mechanism:
Can support very big amount of timers efficiently (tens,
hundreds of millions, billions). It also equally efficient for
delayed and periodic messages.
Because of that timer_wheel mechanism should be used
when the application needs a big number of timers.
But there are some costs...
SObjectizer Team, Jan 2016
Drawbacks of timer_wheel mechanism:
● this mechanism is not very precise (there is a step of
timer wheel which could be configured, but small step
decrease effectiveness);
● this mechanism consumes some resources even if there
are no ready to use timers (this overhead is small but it is
still here).
SObjectizer Team, Jan 2016
timer_list mechanism:
Works very well only if new timers will be added to the end of
list of timers. Therefore this mechanism should be used in
applications where there are many similar delayed
messages with the same delays.
This mechanism does not consume resources when there
are no ready to use timers. It also handles timers
cancellation very efficiently.
SObjectizer Team, Jan 2016
timer_heap mechanism:
Has very fluent overall performance, especially on relative
small amounts of timers (thousands, tens of thousands
timers). It also does not consume resources if there are no
ready to use timers.
Because of that timer_heap mechanism is used in SO
Environment by default.
SObjectizer Team, Jan 2016
For more information about timer mechanisms, their
strengths and weakness see description of Timer Template
Thread (timertt) library. This library is used for
implementation of delayed and periodic messages in SO-
5.5.
SObjectizer Team, Jan 2016
Timer mechanism can be specified in Environment’s
parameters before start of SO Environment:
so_5::launch( []( so_5::environment_t & env ) {
// Some initialization stuff...
},
// SObjectizer Environment parameters tuning.
[]( so_5::environment_params_t & params ) {
// Use timer_wheel mechanism with wheel size 10000
// and timer step size of 5ms.
params.timer_thread(
so_5::timer_wheel_factory( 10000,
std::chrono::milliseconds(5) ) );
...
} );
SObjectizer Team, Jan 2016
Additional Information:
Project’s home: http://sourceforge.net/projects/sobjectizer
Documentation: http://sourceforge.net/p/sobjectizer/wiki/
Forum: http://sourceforge.net/p/sobjectizer/discussion/
Google-group: https://groups.google.com/forum/#!forum/sobjectizer
GitHub mirror: https://github.com/masterspline/SObjectizer

More Related Content

What's hot

arataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world examplearataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world exampleYauheni Akhotnikau
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckAndrey Karpov
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Andrey Karpov
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That CouldPVS-Studio
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioAndrey Karpov
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationMicha Kops
 
Analysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSPVS-Studio
 
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Andrey Karpov
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsCarol McDonald
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6Richard Jones
 
Heading for a Record: Chromium, the 5th Check
Heading for a Record: Chromium, the 5th CheckHeading for a Record: Chromium, the 5th Check
Heading for a Record: Chromium, the 5th CheckPVS-Studio
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxPVS-Studio
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerAndrey Karpov
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Andrey Karpov
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLitePVS-Studio
 

What's hot (20)

What is SObjectizer 5.5
What is SObjectizer 5.5What is SObjectizer 5.5
What is SObjectizer 5.5
 
arataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world examplearataga. SObjectizer and RESTinio in action: a real-world example
arataga. SObjectizer and RESTinio in action: a real-world example
 
PVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd CheckPVS-Studio vs Chromium. 3-rd Check
PVS-Studio vs Chromium. 3-rd Check
 
Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6Date Processing Attracts Bugs or 77 Defects in Qt 6
Date Processing Attracts Bugs or 77 Defects in Qt 6
 
The Little Unicorn That Could
The Little Unicorn That CouldThe Little Unicorn That Could
The Little Unicorn That Could
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Checking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-StudioChecking Clang 11 with PVS-Studio
Checking Clang 11 with PVS-Studio
 
Creating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat ApplicationCreating a Java EE 7 Websocket Chat Application
Creating a Java EE 7 Websocket Chat Application
 
Analysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMSAnalysis of bugs in Orchard CMS
Analysis of bugs in Orchard CMS
 
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1) Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
Miranda NG Project to Get the "Wild Pointers" Award (Part 1)
 
Java7
Java7Java7
Java7
 
my accadanic project ppt
my accadanic project pptmy accadanic project ppt
my accadanic project ppt
 
Java Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and TrendsJava Concurrency, Memory Model, and Trends
Java Concurrency, Memory Model, and Trends
 
What's New In Python 2.6
What's New In Python 2.6What's New In Python 2.6
What's New In Python 2.6
 
Heading for a Record: Chromium, the 5th Check
Heading for a Record: Chromium, the 5th CheckHeading for a Record: Chromium, the 5th Check
Heading for a Record: Chromium, the 5th Check
 
A fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBoxA fresh eye on Oracle VM VirtualBox
A fresh eye on Oracle VM VirtualBox
 
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code AnalyzerRechecking TortoiseSVN with the PVS-Studio Code Analyzer
Rechecking TortoiseSVN with the PVS-Studio Code Analyzer
 
Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?Still Comparing "this" Pointer to Null?
Still Comparing "this" Pointer to Null?
 
Linux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLiteLinux version of PVS-Studio couldn't help checking CodeLite
Linux version of PVS-Studio couldn't help checking CodeLite
 

Similar to Dive into SObjectizer 5.5. Fifth part: Timers

Similar to Dive into SObjectizer 5.5. Fifth part: Timers (20)

What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9What's new in SObjectizer 5.5.9
What's new in SObjectizer 5.5.9
 
What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)What is SObjectizer 5.7 (at v.5.7.0)
What is SObjectizer 5.7 (at v.5.7.0)
 
How to build typing indicator in a Chat app
How to build typing indicator in a Chat appHow to build typing indicator in a Chat app
How to build typing indicator in a Chat app
 
What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)What is SObjectizer 5.6 (at v.5.6.0)
What is SObjectizer 5.6 (at v.5.6.0)
 
RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2RTOS MICRO CONTROLLER OPERATING SYSTEM-2
RTOS MICRO CONTROLLER OPERATING SYSTEM-2
 
Java Messaging Services
Java Messaging ServicesJava Messaging Services
Java Messaging Services
 
Moment.js overview
Moment.js overviewMoment.js overview
Moment.js overview
 
Unix Administration 5
Unix Administration 5Unix Administration 5
Unix Administration 5
 
SAS Macros part 1
SAS Macros part 1SAS Macros part 1
SAS Macros part 1
 
MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message Queueing
 
Java 8 Date and Time API
Java 8 Date and Time APIJava 8 Date and Time API
Java 8 Date and Time API
 
Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
XSS
XSSXSS
XSS
 
XSS
XSSXSS
XSS
 
Inter-Sling communication with message queue
Inter-Sling communication with message queueInter-Sling communication with message queue
Inter-Sling communication with message queue
 
540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf540slidesofnodejsbackendhopeitworkforu.pdf
540slidesofnodejsbackendhopeitworkforu.pdf
 
Angular performance slides
Angular performance slidesAngular performance slides
Angular performance slides
 
JavaScript for real men
JavaScript for real menJavaScript for real men
JavaScript for real men
 

More from Yauheni Akhotnikau

Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Yauheni Akhotnikau
 
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...Yauheni Akhotnikau
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Yauheni Akhotnikau
 
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Yauheni Akhotnikau
 
Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Yauheni Akhotnikau
 
25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My EyesYauheni Akhotnikau
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allYauheni Akhotnikau
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Yauheni Akhotnikau
 
Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Yauheni Akhotnikau
 
Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Yauheni Akhotnikau
 
Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Yauheni Akhotnikau
 
What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8Yauheni Akhotnikau
 
Погружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьПогружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьYauheni Akhotnikau
 

More from Yauheni Akhotnikau (14)

Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)Actor Model and C++: what, why and how? (March 2020 Edition)
Actor Model and C++: what, why and how? (March 2020 Edition)
 
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
[C++ CoreHard Autumn 2018] Actors vs CSP vs Task...
 
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
Shrimp: A Rather Practical Example Of Application Development With RESTinio a...
 
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
Акторы в C++: взгляд старого практикующего актородела (St. Petersburg C++ Use...
 
Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?Акторы на C++: стоило ли оно того?
Акторы на C++: стоило ли оно того?
 
25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes25 Years of C++ History Flashed in Front of My Eyes
25 Years of C++ History Flashed in Front of My Eyes
 
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them allGECon 2017: C++ - a Monster that no one likes but that will outlast them all
GECon 2017: C++ - a Monster that no one likes but that will outlast them all
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?
 
Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++Шишки, набитые за 15 лет использования акторов в C++
Шишки, набитые за 15 лет использования акторов в C++
 
Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?Для чего мы делали свой акторный фреймворк и что из этого вышло?
Для чего мы делали свой акторный фреймворк и что из этого вышло?
 
Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?Модель акторов и C++ что, зачем и как?
Модель акторов и C++ что, зачем и как?
 
What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8What’s new in SObjectizer 5.5.8
What’s new in SObjectizer 5.5.8
 
Погружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная частьПогружение в SObjectizer 5.5. Вводная часть
Погружение в SObjectizer 5.5. Вводная часть
 
Обзор SObjectizer 5.5
Обзор SObjectizer 5.5Обзор SObjectizer 5.5
Обзор SObjectizer 5.5
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Natan Silnitsky
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...OnePlan Solutions
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
Taming Distributed Systems: Key Insights from Wix's Large-Scale Experience - ...
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
Tech Tuesday - Mastering Time Management Unlock the Power of OnePlan's Timesh...
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 

Dive into SObjectizer 5.5. Fifth part: Timers

  • 1. Dive into SObjectizer-5.5 SObjectizer Team, Jan 2016 Fifth Part: Timers (at v.5.5.15)
  • 2. This is the next part of the series of presentations with deep introduction into features of SObjectizer-5.5. This part is dedicated to usage of timers. In particular: ● delayed messages; ● periodic messages; ● cancellation of delayed/periodic messages; ● timer thread and timer mechanisms. SObjectizer Team, Jan 2016
  • 3. Timers are actively used in typical SObjectizer’s based applications. That's why SObjectizer provides easy to use tools for dealing with timers: ● delayed messages; ● periodic messages. SObjectizer Team, Jan 2016
  • 4. A delayed message is delivered after a specified time interval since the message was sent. It means that if a delayed message is sent at some time point T and the delay is 150ms then it will be pushed to subscribers’ event queues at time point (T+150ms). SObjectizer Team, Jan 2016
  • 5. A periodic message is repeatedly delivered after a specified amount of time. It means that if a periodic message is sent at some time point T with delay of 150ms and repetition period of 250ms then it will be pushed to subscribers’ event queues first time at time point (T+150ms), then at time point (T+400ms), then at (T+650ms) and so on. A periodic message will be repeated until it canceled. SObjectizer Team, Jan 2016
  • 7. There are three ways for sending a delayed messages. The simplest one is to use send_delayed() function. A reference to SO Environment instance is necessary for sending a delayed message. That’s why the first argument of send_delayed() is a reference to environment_t or some object from which that reference could be obtained. SObjectizer Team, Jan 2016
  • 8. Sending a delayed message from ordinary agent: class my_agent : public so_5::agent_t { ... virtual void so_evt_start() override { so_5::send_delayed< some_message >( so_environment(), // SO Environment to be used. dest, // Destination mbox. std::chrono::milliseconds(125), // Delivery delay in ms. ... ); // Arguments to be forwarded to some_message constructor. } }; SObjectizer Team, Jan 2016
  • 9. Sending a delayed message from ad-hoc agent: env.introduce_coop( []( so_5::coop_t & coop ) { coop.define_agent().on_start( [&coop] { so_5::send_delayed< some_message >( coop.environment(), // SO Environment to be used. dest, // Destination mbox. std::chrono::milliseconds(125), // Delivery delay in ms. ... ); // Arguments to be forwarded to some_message constructor. ... } ); } ); SObjectizer Team, Jan 2016
  • 10. Function send_delayed can be used to sending a delayed message to the direct mbox of agent-receiver. SO Environment in which the receiver is registered will be used in that case. SObjectizer Team, Jan 2016
  • 11. Sending a delayed message to the direct mbox of the agent- receiver: class my_agent : public so_5::agent_t { ... void evt_request( const request & evt ) { initiate_request_processing( evt ); so_5::send_delayed< check_request >( *this, // Destination for message. std::chrono::milliseconds(125), // Delivery delay in ms. ... ); // Arguments to be forwarded to check_request constructor. } }; SObjectizer Team, Jan 2016
  • 12. Function send_delayed() also accepts an ad-hoc agent proxy: env.introduce_coop( []( so_5::coop_t & coop ) { auto a = coop.define_agent(); a.event( a, [a]( const request & evt ) { initiate_request_processing( evt ); so_5::send_delayed< check_request >( a, // Destination for message. std::chrono::milliseconds(125), // Delivery delay in ms. ... ); // Arguments to be forwarded to check_request constructor. } ); } ); SObjectizer Team, Jan 2016
  • 13. The second way is to use single_timer() method of environment_t class: class my_agent : public so_5::agent_t { ... void evt_request( const request & evt ) { initiate_request_processing( evt ); auto delayed_msg = std::make_unique< check_request >( ... ); so_environment().single_timer( std::move(delayed_msg), // Message instance. so_direct_mbox(), // Destination for message. std::chrono::milliseconds(125) ); // Delivery delay in ms. } }; SObjectizer Team, Jan 2016
  • 14. Usage of single_timer() is not as easy as usage of send_delayed(). But single_timer() can be useful if a message instance is created somewhere else... SObjectizer Team, Jan 2016
  • 15. A case where single_timer() can be useful: class my_agent : public so_5::agent_t { ... void evt_request( const request & evt ) { initiate_request_processing( evt ); so_environment().single_timer( create_check_request_message( evt ), // Message instance. so_direct_mbox(), // Destination for message. std::chrono::milliseconds(125) ); // Delivery delay in ms. } std::unique_ptr< check_request > create_check_request_message( const request & evt ) { ... // Some complex logic. return std::make_unique< check_request >( ... ); } }; SObjectizer Team, Jan 2016
  • 16. The third way is to use schedule_timer() method of environment_t class. Method schedule_timer() returns timer ID which can be used for timer cancellation. SObjectizer Team, Jan 2016
  • 17. An example of delayed message cancellation: class my_agent : public so_5::agent_t { so_5::timer_id_t m_check_timer; ... void evt_request( const request & evt ) { initiate_request_processing( evt ); m_check_timer = so_environment().schedule_timer( create_check_request_message( evt ), // Message instance. so_direct_mbox(), // Destination for message. std::chrono::milliseconds(125), // Delivery delay in ms. std::chrono::milliseconds::zero() ); // No repetition. } void evt_request_processed() { // There is no need for delayed message anymore. m_check_timer.release(); // Cancellation of delivery. ... } std::unique_ptr< check_request > create_check_request_message( const request & evt ) { ... } }; SObjectizer Team, Jan 2016
  • 19. Periodic message are repeated again and again until it will be cancelled. The same message instance is delivered every time. It means that message instance is not deallocated after processing. Deallocation will occur when message will be cancelled. SObjectizer Team, Jan 2016
  • 20. There are two ways for sending a periodic message. The simplest one is to use send_periodic() function. As for delayed messages the access to SO Environment is necessary for sending a periodic message. That’s why the first argument of send_periodic() must be a reference to environment_t or some object from which that reference could be obtained. SObjectizer Team, Jan 2016
  • 21. Sending of a periodic message from ordinary agent: class my_agent : public so_5::agent_t { so_5::timer_id_t m_status_timer; ... virtual void so_evt_start() override { m_status_timer = so_5::send_periodic< update_status >( so_environment(), // SO Environment to be used. dest, // Destination mbox. std::chrono::milliseconds(125), // First delivery delay in ms. std::chrono::milliseconds(250), // Repetition period in ms. ... ); // Arguments to be forwarded to update_status constructor. } }; SObjectizer Team, Jan 2016
  • 22. Function send_periodic() can send a message to the direct mbox of the agent-receiver: class my_agent : public so_5::agent_t { so_5::timer_id_t m_status_timer; ... virtual void so_evt_start() override { m_status_timer = so_5::send_periodic< update_status >( *this, // Destination. SO Environment of target agent will be used. std::chrono::milliseconds(125), // First delivery delay in ms. std::chrono::milliseconds(250), // Repetition period in ms. ... ); // Arguments to be forwarded to update_status constructor. } }; SObjectizer Team, Jan 2016
  • 23. The second way is to use schedule_timer() method of environment_t class: class my_agent : public so_5::agent_t { so_5::timer_id_t m_status_timer; ... virtual void so_evt_start() override { m_status_timer = so_environment().schedule_timer( create_status_message(), // Message to be sent periodically. so_direct_mbox(), // Destination. std::chrono::milliseconds(125), // First delivery delay in ms. std::chrono::milliseconds(250) ); // Repetition period in ms. } std::unique_ptr< update_status > create_status_message() { ... } }; SObjectizer Team, Jan 2016
  • 24. The most important moment in periodic messages sending ‒ is storing the result value of send_periodic() and schedule_timer(). If the result value is not saved then periodic message will be cancelled immediately. This is because the destructor of timer_id_t does timer cancellation. SObjectizer Team, Jan 2016
  • 25. The so_5::timer_id_t class works like a smart pointer. Destruction of the last timer_id_t pointed to a timer will destroy the timer and periodic (or delayed) message will be cancelled. That’s why at least one timer_id_t object for periodic message must exist while message delivery is necessary. SObjectizer Team, Jan 2016
  • 27. There are three ways of delayed/periodic messages cancellation. All of them use timer_id_t objects. It means that cancellation is only possible for messages sent via send_periodic() or schedule_timer(). SObjectizer Team, Jan 2016
  • 28. The first way is to call release() method of timer_id_t class. auto id = so_5::send_periodic< Msg >(...); ... id.release(); // Delivery canceled. Please note that explicit call of release() method cancels a message regardless of count of remaining timer_id_t objects pointed to that timer. SObjectizer Team, Jan 2016
  • 29. The second way is destruction of all timer_id_t objects pointing to the same timer. If release() method is not called explicitly it will be called in the destructor of the last timer_id_t object pointing to a timer. This way is often used in ordinary agents: class request_processor : public so_5::agent_t { so_5::timer_id_t m_check_request; ... void evt_request( const request & evt ) { m_check_request = so_5::send_periodic< check_request >( *this, ...); // Timer will be cancelled automatically in // the destructor of request_processor. ... } }; SObjectizer Team, Jan 2016
  • 30. The third way is assignment of new value to timer_id_t object. If this object was the last timer_id_t pointed to a timer then the timer will be destroyed and message will be cancelled: auto id = so_5::send_periodic< Msg >(...); ... // Some actions. id = so_5::send_periodic< Sig >(...); // Cancellation of Msg. SObjectizer Team, Jan 2016
  • 31. There is a trick moment with cancellation of delayed messages... Delayed message will be cancelled only if it is still under control of timer thread. If message already leaved timer thread and is waiting in event queues of recipients then message delivery will not be cancelled and message will be processed by subscribers. For example if delay was 125ms and cancelaction is initiated after 125ms after call to send_delayed there is a high probability that message will be delivered anyway. SObjectizer Team, Jan 2016
  • 33. SO Environment starts a special thread for handling timers. This thread is known as timer thread. All timers are controlled and processed by that timer thread. Timer thread can efficiently process big amount of timers: tens and hundreds of millions. Even billions of timers. A user can choose a timer mechanism most appropriate for application needs. SObjectizer Team, Jan 2016
  • 34. Three timer mechanisms are supported. Each has its strengths and weakness: ● timer_wheel ● timer_list ● timer_heap SObjectizer Team, Jan 2016
  • 35. timer_wheel mechanism: Can support very big amount of timers efficiently (tens, hundreds of millions, billions). It also equally efficient for delayed and periodic messages. Because of that timer_wheel mechanism should be used when the application needs a big number of timers. But there are some costs... SObjectizer Team, Jan 2016
  • 36. Drawbacks of timer_wheel mechanism: ● this mechanism is not very precise (there is a step of timer wheel which could be configured, but small step decrease effectiveness); ● this mechanism consumes some resources even if there are no ready to use timers (this overhead is small but it is still here). SObjectizer Team, Jan 2016
  • 37. timer_list mechanism: Works very well only if new timers will be added to the end of list of timers. Therefore this mechanism should be used in applications where there are many similar delayed messages with the same delays. This mechanism does not consume resources when there are no ready to use timers. It also handles timers cancellation very efficiently. SObjectizer Team, Jan 2016
  • 38. timer_heap mechanism: Has very fluent overall performance, especially on relative small amounts of timers (thousands, tens of thousands timers). It also does not consume resources if there are no ready to use timers. Because of that timer_heap mechanism is used in SO Environment by default. SObjectizer Team, Jan 2016
  • 39. For more information about timer mechanisms, their strengths and weakness see description of Timer Template Thread (timertt) library. This library is used for implementation of delayed and periodic messages in SO- 5.5. SObjectizer Team, Jan 2016
  • 40. Timer mechanism can be specified in Environment’s parameters before start of SO Environment: so_5::launch( []( so_5::environment_t & env ) { // Some initialization stuff... }, // SObjectizer Environment parameters tuning. []( so_5::environment_params_t & params ) { // Use timer_wheel mechanism with wheel size 10000 // and timer step size of 5ms. params.timer_thread( so_5::timer_wheel_factory( 10000, std::chrono::milliseconds(5) ) ); ... } ); SObjectizer Team, Jan 2016
  • 41. Additional Information: Project’s home: http://sourceforge.net/projects/sobjectizer Documentation: http://sourceforge.net/p/sobjectizer/wiki/ Forum: http://sourceforge.net/p/sobjectizer/discussion/ Google-group: https://groups.google.com/forum/#!forum/sobjectizer GitHub mirror: https://github.com/masterspline/SObjectizer