Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
f5e61e27
Commit
f5e61e27
authored
Jun 12, 2017
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track batch IDs properly, improve upstream policy
parent
b7e22236
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
51 additions
and
26 deletions
+51
-26
libcaf_core/caf/stream_handler.hpp
libcaf_core/caf/stream_handler.hpp
+4
-3
libcaf_core/caf/stream_sink.hpp
libcaf_core/caf/stream_sink.hpp
+2
-2
libcaf_core/caf/stream_stage.hpp
libcaf_core/caf/stream_stage.hpp
+1
-1
libcaf_core/caf/upstream_policy.hpp
libcaf_core/caf/upstream_policy.hpp
+3
-0
libcaf_core/src/stream_handler.cpp
libcaf_core/src/stream_handler.cpp
+2
-1
libcaf_core/src/stream_msg_visitor.cpp
libcaf_core/src/stream_msg_visitor.cpp
+1
-1
libcaf_core/src/stream_sink.cpp
libcaf_core/src/stream_sink.cpp
+3
-3
libcaf_core/src/stream_source.cpp
libcaf_core/src/stream_source.cpp
+19
-6
libcaf_core/src/stream_stage.cpp
libcaf_core/src/stream_stage.cpp
+3
-2
libcaf_core/src/upstream_policy.cpp
libcaf_core/src/upstream_policy.cpp
+8
-4
libcaf_core/test/manual_stream_management.cpp
libcaf_core/test/manual_stream_management.cpp
+5
-3
No files found.
libcaf_core/caf/stream_handler.hpp
View file @
f5e61e27
...
...
@@ -66,11 +66,12 @@ public:
/// Add a new upstream actor to the stream and return an initial credit.
virtual
expected
<
long
>
add_upstream
(
strong_actor_ptr
&
hdl
,
const
stream_id
&
sid
,
stream_priority
prio
);
const
stream_id
&
sid
,
stream_priority
prio
);
/// Handles data from an upstream actor.
virtual
error
upstream_batch
(
strong_actor_ptr
&
hdl
,
long
,
message
&
xs
);
virtual
error
upstream_batch
(
strong_actor_ptr
&
hdl
,
int64_t
xs_id
,
long
xs_size
,
message
&
xs
);
/// Closes an upstream.
virtual
error
close_upstream
(
strong_actor_ptr
&
hdl
);
...
...
libcaf_core/caf/stream_sink.hpp
View file @
f5e61e27
...
...
@@ -41,8 +41,8 @@ public:
bool
done
()
const
override
;
error
upstream_batch
(
strong_actor_ptr
&
src
,
long
xs_size
,
message
&
xs
)
override
;
error
upstream_batch
(
strong_actor_ptr
&
src
,
int64_t
xs_id
,
long
xs_size
,
message
&
xs
)
override
;
void
abort
(
strong_actor_ptr
&
cause
,
const
error
&
reason
)
override
;
...
...
libcaf_core/caf/stream_stage.hpp
View file @
f5e61e27
...
...
@@ -45,7 +45,7 @@ public:
error
downstream_demand
(
strong_actor_ptr
&
,
long
)
override
;
error
upstream_batch
(
strong_actor_ptr
&
,
long
,
message
&
)
override
;
error
upstream_batch
(
strong_actor_ptr
&
,
int64_t
,
long
,
message
&
)
override
;
void
last_upstream_closed
();
...
...
libcaf_core/caf/upstream_policy.hpp
View file @
f5e61e27
...
...
@@ -137,6 +137,9 @@ protected:
/// Assigns new credit to upstream actors by filling `assignment_vec_`.
virtual
void
fill_assignment_vec
(
long
downstream_credit
)
=
0
;
/// Creates initial credit for `ptr`.
virtual
long
initial_credit
(
upstream_path
*
ptr
,
long
downstream_credit
);
/// Pointer to the parent actor.
local_actor
*
self_
;
...
...
libcaf_core/src/stream_handler.cpp
View file @
f5e61e27
...
...
@@ -59,7 +59,8 @@ expected<long> stream_handler::add_upstream(strong_actor_ptr&, const stream_id&,
return
sec
::
cannot_add_upstream
;
}
error
stream_handler
::
upstream_batch
(
strong_actor_ptr
&
,
long
,
message
&
)
{
error
stream_handler
::
upstream_batch
(
strong_actor_ptr
&
,
int64_t
,
long
,
message
&
)
{
CAF_LOG_ERROR
(
"Received upstream messages in "
"a stream marked as no-upstreams"
);
return
sec
::
invalid_upstream
;
...
...
libcaf_core/src/stream_msg_visitor.cpp
View file @
f5e61e27
...
...
@@ -118,7 +118,7 @@ auto stream_msg_visitor::operator()(stream_msg::ack_open& x) -> result_type {
auto
stream_msg_visitor
::
operator
()(
stream_msg
::
batch
&
x
)
->
result_type
{
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
if
(
i_
!=
e_
)
return
{
i_
->
second
->
upstream_batch
(
self_
->
current_sender
(),
return
{
i_
->
second
->
upstream_batch
(
self_
->
current_sender
(),
x
.
id
,
static_cast
<
long
>
(
x
.
xs_size
),
x
.
xs
),
i_
};
CAF_LOG_DEBUG
(
"received stream_msg::batch for unknown stream"
);
...
...
libcaf_core/src/stream_sink.cpp
View file @
f5e61e27
...
...
@@ -42,14 +42,14 @@ bool stream_sink::done() const {
return
in_ptr_
->
closed
();
}
error
stream_sink
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
long
xs_size
,
message
&
xs
)
{
error
stream_sink
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
int64_t
xs_id
,
long
xs_size
,
message
&
xs
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
)
<<
CAF_ARG
(
xs_size
)
<<
CAF_ARG
(
xs
));
auto
path
=
in
().
find
(
hdl
);
if
(
path
)
{
if
(
xs_size
>
path
->
assigned_credit
)
return
sec
::
invalid_stream_state
;
path
->
last_batch_id
=
xs_id
;
path
->
assigned_credit
-=
xs_size
;
auto
err
=
consume
(
xs
);
if
(
err
==
none
)
...
...
libcaf_core/src/stream_source.cpp
View file @
f5e61e27
...
...
@@ -47,12 +47,25 @@ error stream_source::downstream_demand(strong_actor_ptr& hdl, long value) {
path
->
open_credit
+=
value
;
if
(
!
at_end
())
{
// produce new elements
auto
current_size
=
buf_size
();
auto
size_hint
=
std
::
min
(
out
().
credit
(),
out
().
max_batch_size
());
if
(
current_size
<
size_hint
)
generate
(
static_cast
<
size_t
>
(
size_hint
-
current_size
));
return
push
();
auto
capacity
=
out
().
credit
();
// TODO: fix issue where a source does not emit the last pieces if
// min_batch_size cannot be reached
while
(
capacity
>
out
().
min_batch_size
())
{
auto
current_size
=
buf_size
();
auto
size_hint
=
std
::
min
(
capacity
,
out
().
max_batch_size
());
if
(
size_hint
>
current_size
)
generate
(
static_cast
<
size_t
>
(
size_hint
-
current_size
));
auto
err
=
push
();
if
(
err
)
return
err
;
// Check if `push` did actually use credit, otherwise break loop
auto
new_capacity
=
out
().
credit
();
if
(
new_capacity
!=
capacity
)
capacity
=
new_capacity
;
else
break
;
}
return
none
;
}
// transmit cached elements before closing paths
if
(
buf_size
()
>
0
)
...
...
libcaf_core/src/stream_stage.cpp
View file @
f5e61e27
...
...
@@ -37,13 +37,14 @@ bool stream_stage::done() const {
return
in_ptr_
->
closed
()
&&
out_ptr_
->
closed
();
}
error
stream_stage
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
long
xs_size
,
message
&
xs
)
{
error
stream_stage
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
int64_t
xs_id
,
long
xs_size
,
message
&
xs
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
)
<<
CAF_ARG
(
xs_size
)
<<
CAF_ARG
(
xs
));
auto
path
=
in
().
find
(
hdl
);
if
(
path
)
{
if
(
xs_size
>
path
->
assigned_credit
)
return
sec
::
invalid_stream_state
;
path
->
last_batch_id
=
xs_id
;
path
->
assigned_credit
-=
xs_size
;
auto
err
=
process_batch
(
xs
);
if
(
err
==
none
)
{
...
...
libcaf_core/src/upstream_policy.cpp
View file @
f5e61e27
...
...
@@ -55,20 +55,19 @@ void upstream_policy::assign_credit(long downstream_capacity) {
for
(
auto
&
x
:
assignment_vec_
)
used_capacity
+=
static_cast
<
long
>
(
x
.
first
->
assigned_credit
);
CAF_LOG_DEBUG
(
CAF_ARG
(
used_capacity
));
if
(
used_capacity
>=
downstream_capacity
)
return
;
fill_assignment_vec
(
downstream_capacity
-
used_capacity
);
for
(
auto
&
x
:
assignment_vec_
)
{
auto
n
=
x
.
second
;
if
(
n
>
0
)
{
auto
ptr
=
x
.
first
;
ptr
->
assigned_credit
+=
n
;
ptr
->
last_acked_batch_id
=
ptr
->
last_batch_id
;
CAF_LOG_DEBUG
(
"ack batch"
<<
ptr
->
last_batch_id
<<
"with"
<<
n
<<
"new capacity"
);
unsafe_send_as
(
self_
,
ptr
->
hdl
,
make
<
stream_msg
::
ack_batch
>
(
ptr
->
sid
,
static_cast
<
int32_t
>
(
n
),
ptr
->
last_batch_id
++
));
ptr
->
last_batch_id
));
}
}
}
...
...
@@ -85,7 +84,7 @@ expected<long> upstream_policy::add_path(strong_actor_ptr hdl,
paths_
.
emplace_back
(
ptr
);
assignment_vec_
.
emplace_back
(
ptr
,
0
);
if
(
downstream_credit
>
0
)
ptr
->
assigned_credit
=
std
::
min
(
max_credit_
,
downstream_credit
);
ptr
->
assigned_credit
=
initial_credit
(
ptr
,
downstream_credit
);
CAF_LOG_DEBUG
(
"add new upstraem path"
<<
ptr
->
hdl
<<
"with initial credit"
<<
ptr
->
assigned_credit
);
return
ptr
->
assigned_credit
;
...
...
@@ -133,4 +132,9 @@ upstream_path* upstream_policy::find(const strong_actor_ptr& x) const {
return
i
!=
e
?
i
->
get
()
:
nullptr
;
}
long
upstream_policy
::
initial_credit
(
upstream_path
*
ptr
,
long
downstream_credit
)
{
return
std
::
min
(
max_credit_
,
downstream_credit
);
}
}
// namespace caf
libcaf_core/test/manual_stream_management.cpp
View file @
f5e61e27
...
...
@@ -151,7 +151,8 @@ public:
expected
<
long
>
add_upstream
(
strong_actor_ptr
&
hdl
,
const
stream_id
&
sid
,
stream_priority
prio
)
override
;
error
upstream_batch
(
strong_actor_ptr
&
hdl
,
long
,
message
&
xs
)
override
;
error
upstream_batch
(
strong_actor_ptr
&
hdl
,
int64_t
,
long
,
message
&
xs
)
override
;
error
close_upstream
(
strong_actor_ptr
&
hdl
)
override
;
...
...
@@ -324,8 +325,8 @@ expected<long> stream_governor::add_upstream(strong_actor_ptr& hdl,
return
sec
::
invalid_argument
;
}
error
stream_governor
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
long
xs_size
,
message
&
xs
)
{
error
stream_governor
::
upstream_batch
(
strong_actor_ptr
&
hdl
,
int64_t
xs_id
,
long
xs_size
,
message
&
xs
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
hdl
)
<<
CAF_ARG
(
xs_size
)
<<
CAF_ARG
(
xs
));
using
std
::
get
;
// Sanity checking.
...
...
@@ -341,6 +342,7 @@ error stream_governor::upstream_batch(strong_actor_ptr& hdl, long xs_size,
// Decrease credit assigned to `hdl` and get currently available downstream
// credit on all paths.
CAF_LOG_DEBUG
(
CAF_ARG
(
path
->
assigned_credit
));
path
->
last_batch_id
=
xs_id
;
path
->
assigned_credit
-=
xs_size
;
// Forward data to all other peers.
for
(
auto
&
kvp
:
peers_
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment