Neverlord on master
Add latest API additions to the… (compare)
Neverlord on 0.18
Enable CI via Cirrus Handle void results in fan_out_… (compare)
Neverlord on neverlord
Add test suite for flow::op::ce… Fix subscription and event hand… More op::buffer coverage; make … (compare)
Neverlord on master
Add flag for net module Merge pull request #1374 (compare)
Neverlord on add-net-module-flag
josephnoir on add-net-module-flag
Add flag for net module (compare)
Neverlord on 1368
How much boilerplate would that be? I imagine it to just be a single function call, which seems acceptable for embedding it in the typed actor signature:
[self](caf::stream<T> handle) -> caf::result<caf::stream_ack<T>>> {
auto [observable, ack] = self->observe_stream(handle);
std::move(observable).for_each(...);
return ack; // could also return an error, or a delegated<stream_ack<T>> here
},
If I understand correctly, a stream in the new model is just a shared spmc buffer resource with a few extra features built on top to allow for some routing and back pressure propagation. Any actor can create a hot observable from stream, and similar any actor can turn a hot observable into a stream. Is this mental model correct?
observe_stream
. That's going to be fine. I was talking about the internal workings of observe_stream
.
I've just assembled a new web_socket::accept
function that nicely integrates with flows: https://github.com/actor-framework/actor-framework/blob/070b3ae157ed7866cf3c9785ca8fceead415ae92/examples/web_socket/echo.cpp.
I wouldn't recommend checking out the caf-net
branch quite yet, though. 🙂
Hello, @Neverlord! We have library(dll) that exports some functions. Inside this functions we have this pseudo code
caf::scoped_actor self{system_->system()};
self
->request(actor1, atom1, ...)
.receive(
[&](....) {
....
},
[&](caf::error& err) {
....
});
Cause this library methods should return result we use blocking behavior.
If we use this library from Qt application actor1 recieves atom1 almost instantly (1-2ms) after calling request. Otherwise if we call this same method from console app actor1 recieves atom1 after a delay of 10-15ms. Cause we call this function multiple times this delay seems critical. We don't understand the reason of this behavior nor how to overcome this :(.
--dump-config
or in source code get_or(<key>, <default>)
. But if you're not setting anything then it's 10ms. It seems like your example does ultimately the same loop, though. So it's weird that it behaves differently when calling it from a Qt thread.
10-15ms seems like a lot. I don't really see what "Qt app" vs "console app" entails, though. Did you maybe reproduce this with some small-ish code that I could look at?
@Neverlord this is ok or "a lot"?
#include <string>
#include <iostream>
#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
#include "caf/caf_main.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/timestamp.hpp"
using namespace caf;
behavior testee() {
return {
[](timestamp t0) {
auto t1 = make_timestamp();
auto delta = t1 - t0;
std::cout << "t0: " << caf::deep_to_string(t0) << '\n'
<< "t1: " << caf::deep_to_string(t1) << '\n'
<< "delta: " << caf::deep_to_string(delta) << '\n';
},
};
}
void caf_main(actor_system& sys) {
scoped_actor self{sys};
auto aut = self->spawn(testee);
self->send(aut, make_timestamp());
}
CAF_MAIN()
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:13:01.901"
t1: "2022-05-09T19:13:01.901"
delta: 52us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:22.067"
t1: "2022-05-09T19:14:22.067"
delta: 26us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:22.945"
t1: "2022-05-09T19:14:22.945"
delta: 19us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:23.442"
t1: "2022-05-09T19:14:23.442"
delta: 89us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:23.921"
t1: "2022-05-09T19:14:23.922"
delta: 94us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:24.403"
t1: "2022-05-09T19:14:24.403"
delta: 26us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:24.827"
t1: "2022-05-09T19:14:24.827"
delta: 68us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
t0: "2022-05-09T19:14:25.242"
t1: "2022-05-09T19:14:25.242"
delta: 23us
#include <string>
#include <iostream>
#include "caf/actor_ostream.hpp"
#include "caf/actor_system.hpp"
#include "caf/caf_main.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/timestamp.hpp"
using namespace caf;
using namespace std::literals;
behavior clock_actor() {
return {
[](get_atom) {
return make_timestamp();
}
};
}
behavior testee() {
return {
[](timestamp t0) {
auto t1 = make_timestamp();
auto delta = t1 - t0;
std::cout << "async:\n"
<< "t0: " << caf::deep_to_string(t0) << '\n'
<< "t1: " << caf::deep_to_string(t1) << '\n'
<< "delta: " << caf::deep_to_string(delta) << '\n';
},
};
}
void caf_main(actor_system& sys) {
scoped_actor self{sys};
// request-response
auto clk = self->spawn(clock_actor);
auto t0 = make_timestamp();
self->request(clk, 5s, get_atom_v)
.receive(
[&](timestamp t1) {
auto t2 = make_timestamp();
std::cout << "request-response:\n"
<< "t0: " << caf::deep_to_string(t0) << '\n'
<< "t1: " << caf::deep_to_string(t1) << '\n'
<< "t2: " << caf::deep_to_string(t2) << '\n'
<< "delta (full): " << caf::deep_to_string(t2 - t0) << '\n'
<< "delta (self -> clock): " << caf::deep_to_string(t1 - t0) << '\n'
<< "delta (clock -> self): " << caf::deep_to_string(t2 - t1) << '\n';
},
[](const error&) {});
// async
auto aut = self->spawn(testee);
self->send(aut, make_timestamp());
}
CAF_MAIN()
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:10.369"
t1: "2022-05-09T19:24:10.369"
t2: "2022-05-09T19:24:10.369"
delta (full): 52us
delta (self -> clock): 43us
delta (clock -> self): 9us
async:
t0: "2022-05-09T19:24:10.370"
t1: "2022-05-09T19:24:10.370"
delta: 73us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:11.077"
t1: "2022-05-09T19:24:11.077"
t2: "2022-05-09T19:24:11.077"
delta (full): 51us
delta (self -> clock): 35us
delta (clock -> self): 16us
async:
t0: "2022-05-09T19:24:11.077"
t1: "2022-05-09T19:24:11.078"
delta: 70us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:11.693"
t1: "2022-05-09T19:24:11.693"
t2: "2022-05-09T19:24:11.693"
delta (full): 111us
delta (self -> clock): 20us
delta (clock -> self): 91us
async:
t0: "2022-05-09T19:24:11.694"
t1: "2022-05-09T19:24:11.694"
delta: 16us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:12.277"
t1: "2022-05-09T19:24:12.277"
t2: "2022-05-09T19:24:12.277"
delta (full): 67us
delta (self -> clock): 51us
delta (clock -> self): 16us
async:
t0: "2022-05-09T19:24:12.278"
t1: "2022-05-09T19:24:12.278"
delta: 61us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:12.847"
t1: "2022-05-09T19:24:12.847"
t2: "2022-05-09T19:24:12.847"
delta (full): 40us
delta (self -> clock): 30us
delta (clock -> self): 10us
async:
t0: "2022-05-09T19:24:12.848"
t1: "2022-05-09T19:24:12.848"
delta: 44us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:13.390"
t1: "2022-05-09T19:24:13.390"
t2: "2022-05-09T19:24:13.390"
delta (full): 56us
delta (self -> clock): 46us
delta (clock -> self): 10us
async:
t0: "2022-05-09T19:24:13.391"
t1: "2022-05-09T19:24:13.391"
delta: 38us
@iMacWork: ~/workspace # master $ ./build/caf/release/examples/hello_world
request-response:
t0: "2022-05-09T19:24:13.963"
t1: "2022-05-09T19:24:13.963"
t2: "2022-05-09T19:24:13.963"
delta (full): 128us
delta (self -> clock): 118us
delta (clock -> self): 10us
async:
t0: "2022-05-09T19:24:13.963"
t1: "2022-05-09T19:24:13.963"
delta: 15us
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:01:47.152"
t1: "2022-05-11T09:01:47.152"
t2: "2022-05-11T09:01:47.152"
delta (full): 195.5us
delta (self -> clock): 171.1us
delta (clock -> self): 24.4us
async:
t0: "2022-05-11T09:01:47.154"
t1: "2022-05-11T09:01:47.167"
delta: 12.1155ms
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:03:42.867"
t1: "2022-05-11T09:03:42.867"
t2: "2022-05-11T09:03:42.867"
delta (full): 143.1us
delta (self -> clock): 107.9us
delta (clock -> self): 35.2us
async:
t0: "2022-05-11T09:03:42.869"
t1: "2022-05-11T09:03:42.871"
delta: 1.6837ms
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:03:44.086"
t1: "2022-05-11T09:03:44.087"
t2: "2022-05-11T09:03:44.087"
delta (full): 206.8us
delta (self -> clock): 191.5us
delta (clock -> self): 15.3us
async:
t0: "2022-05-11T09:03:44.089"
t1: "2022-05-11T09:03:44.090"
delta: 766.6us
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:03:45.375"
t1: "2022-05-11T09:03:45.376"
t2: "2022-05-11T09:03:45.376"
delta (full): 88.3us
delta (self -> clock): 70.6us
delta (clock -> self): 17.7us
async:
t0: "2022-05-11T09:03:45.378"
t1: "2022-05-11T09:03:45.389"
delta: 11.0762ms
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:03:46.646"
t1: "2022-05-11T09:03:46.646"
t2: "2022-05-11T09:03:46.646"
delta (full): 129.1us
delta (self -> clock): 106.2us
delta (clock -> self): 22.9us
async:
t0: "2022-05-11T09:03:46.648"
t1: "2022-05-11T09:03:46.655"
delta: 6.2401ms
alexey@DESKTOP-2KI1PTN C:\Users\Alexey\Documents\caf-request-recieve\build-Release-msvc_2019_x86\bin>"C:/Users/Alexey/Documents/caf-request-recieve/build-Release-msvc_2019_x86/bin/console_caf.exe"
request-response:
t0: "2022-05-11T09:03:47.915"
t1: "2022-05-11T09:03:47.915"
t2: "2022-05-11T09:03:47.915"
delta (full): 228.6us
delta (self -> clock): 200.6us
delta (clock -> self): 28us
async:
t0: "2022-05-11T09:03:47.918"
t1: "2022-05-11T09:03:47.920"
delta: 2.6073ms