Crates.io | tros |
lib.rs | tros |
version | 0.2.0 |
source | src |
created_at | 2024-01-30 12:59:53.984762 |
updated_at | 2024-11-01 15:55:10.943399 |
description | Your tros from tarantool TX thread to tokio(..and others!) |
homepage | https://git.picodata.io/picodata/modules/tros |
repository | https://git.picodata.io/picodata/modules/tros |
max_upload_size | |
id | 1120202 |
size | 20,497 |
tros
- your tros to tokio(...and others)Tros
is an off line tarantool executor.
It is your bridge from TX thread to ordinary external threads - namely, to the tokio
runtime.
To get a quick glimpse of what it offers, lets make an async HTTP request with it:
let text = TokioExecutor::new(PicodataTransport::default())
.exec(async { reqwest::get("http://example.com").await?.text().await })
.unwrap()
.unwrap();
assert!(text.contains("Example Domain"))
Internally it would go through the following steps:
tokio
runtime if it doesn't exist yet;To get started, first understand what tarantool version you are using.
You can do it via tarantool --version
.
If it says picodata
somewhere, then you are using our fork, which means we can give you some optimizations, congrats! 🥳
If it doesn't say picodata
, then you are on vanilla tarantool.
Then take a look at the table below to pick needed features and items:
TT Version | Cargo feature | What it enables |
---|---|---|
Picodata fork | picodata |
PicodataTransport |
Vanilla | vanilla |
VanillaTransport |
Install tros
with the needed feature by adding it to Cargo.toml
, for example: tros = { version = "0.1.0", features = [ "picodata" ] }
Use enabled transports in your code, for example:
TokioExecutor::new(PicodataTransport::default()).exec(...)
;TokioExecutor::new(VanillaTransport::default()).exec(...)
;Normally you should not choose transport yourself. Just pick a suitable feature as described above and you are good to go with the automatically selected transport.
If you are indeed interested in the underlying transport details, take a look at transport comparison table:
Type | Description | Pros | Cons |
---|---|---|---|
CBusTransport |
It uses CBus oneshot channel to receive job result. |
As it uses CBus channel, it is very efficient: it simply puts current fiber to sleep and, as a result, doesn't waste additional resources. |
For the moment of writing, it is only available in the picodata fork. There is an ongoing effort to push CBus patch to the upstream. |
PollTransport |
It polls underlying channel with the configurable interval to receive job result. | It is available in all modern tarantool versions. | As it polls channel with some interval, it is not very efficient. |
Examples are placed in example
crate. To simplify their execution, each example is just tarantool test.
To run and check examples, install tarantool-test
binary and run make run-examples
.