Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/[SE] scheduler #992

Merged
merged 1 commit into from Apr 27, 2021

Conversation

iceseer
Copy link
Contributor

@iceseer iceseer commented Apr 26, 2021

Description of the Change

Added scheduler with execution thread loop. Can be used to manage your own process loop in a current thread.

Benefits

Possible Drawbacks

Usage Examples or Tests [optional]

Alternate Designs [optional]

@iceseer iceseer force-pushed the feature/se_scheduler branch 2 times, most recently from 5bee6ad to b43e11a Compare April 26, 2021 16:09
@iceseer iceseer force-pushed the feature/se_scheduler branch 2 times, most recently from d9b877d to 3ee170e Compare April 26, 2021 16:31
auto tid = manager->dispatcher()->bind(scheduler);
ASSERT_TRUE(tid);

utils::WaitForSingleObject complete[2];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
utils::WaitForSingleObject complete[2];

Can be removed because the test is single-threaded.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* @and they subscribe to different events in a single current scheduler
* @and both events are notified followed by dispose and process
* @then the handlers of each subscriber must be called once and process finish
* it's loop
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* it's loop
* its loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

}

bool unbind(Tid tid) override {
return binded_.exclusiveAccess([tid](BoundContexts &bound) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return binded_.exclusiveAccess([tid](BoundContexts &bound) {
return bound_.exclusiveAccess([tid](BoundContexts &bound) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

private:
using Parent = IDispatcher<kCount, kPoolSize>;
using Parent = IDispatcher;

struct ThreadHandlerContext {
/// Worker thread to execute tasks
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a thread from now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree

}

void addDelayed(std::chrono::microseconds timeout, Task &&t) override {
#ifdef SE_SYNC_CALL_IF_SAME_THREAD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use templated constant or constexpr contruction-time constant or anything but not define.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template parameter allows you to execute both kind of code. But you can't.

* If you need to execute task, that was made in this thread and want to be
* executed in the same thread without delay - you need to uncomment this define
*/
//#define SE_SYNC_CALL_IF_SAME_THREAD
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no-no-no! Looks like a dead code in future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

@@ -6,6 +6,7 @@
#ifndef IROHA_SUBSCRIPTION_SUBSCRIPTION_ENGINE_HPP
#define IROHA_SUBSCRIPTION_SUBSCRIPTION_ENGINE_HPP

#include <assert.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include <assert.h>
#include <cassert>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static_assert is not defined in cassert

@@ -91,18 +92,17 @@ namespace iroha::subscription {
* be kept valid in case the other subscriber will be deleted from this
* container)
*/
template <typename Dispatcher::Tid kTid>
IteratorType subscribe(SubscriptionSetId set_id,
IteratorType subscribe(typename Dispatcher::Tid tid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls also fix doc @tparam

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment on lines 665 to 666
subscriber1->subscribe(1ull, event_id);
subscriber2->subscribe(1ull, event_id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
subscriber1->subscribe(1ull, event_id);
subscriber2->subscribe(1ull, event_id);
subscriber1->subscribe(1, event_id);
subscriber2->subscribe(1, event_id);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If so, we need 1u. 1 is a signed int type.

if (!scheduler)
return std::nullopt;

return bound_.exclusiveAccess([scheduler(std::move(scheduler))](
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for readability less parenthes:

Suggested change
return bound_.exclusiveAccess([scheduler(std::move(scheduler))](
return bound_.exclusiveAccess([scheduler=std::move(scheduler)](

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning here is the construction of an object and you need to call it as a constructor.

BoundContexts &bound) {
auto const execution_tid = kHandlersCount + bound.next_tid_offset;
assert(bound.contexts.find(execution_tid) == bound.contexts.end());
bound.contexts[execution_tid] = ThreadHandlerContext{scheduler, false};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have replaced terminology ThreadHandler with Sceduler - pls rename class.

Suggested change
bound.contexts[execution_tid] = ThreadHandlerContext{scheduler, false};
bound.contexts[execution_tid] = ShedulerContext{scheduler, false};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

try {
if (task)
task();
} catch (...) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure? let's log error at least!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the last barrier


class SchedulerBase : public IScheduler, utils::NoCopy, utils::NoMove {
private:
using Time = std::chrono::high_resolution_clock;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer same terminology as std:: and boost::

Suggested change
using Time = std::chrono::high_resolution_clock;
using Clock = std::chrono::high_resolution_clock;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like time and timestamp much more than clock and time-point.

bind/unbind additional schedulers to dispatcher

Signed-off-by: iceseer <iceseer@gmail.com>
@iceseer iceseer merged commit 4569564 into hyperledger:support/1.2.x Apr 27, 2021
@iceseer iceseer deleted the feature/se_scheduler branch April 27, 2021 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants