Comments (7)
The underlying connection type would need a mutable reference to write any data (see impl and definition for the Write
and AsyncWrite
traits), which is why the actions accept mutable references. In Rust, mutable references are mutually exclusive to immutable references (so you can have a single &mut T
or multiple &T
s).
Regarding sending queries concurrently (and assuming you do not mean parallelism), in this library-specific scenario, you can utilize pipelining to send multiple queries at the same time. Multiplexed queries are still experimental (and not available for public use right now).
from client-rust.
If you wanted to utilize multiple threads for sending queries, considering looking at the available connection pool implementations: https://docs.rs/skytable/latest/skytable/pool/index.html
from client-rust.
You're referring to, e.g., AsyncWrite
here?
Line 426 in c57e46e
I see that you're mutating stream
in implementing tokio::io::AsyncWrite
, and that forces the existence of an &mut
.
But maybe you could use a mutex here to serialize the writes, so the API one level up wouldn't need to take an &mut
?
If the writes are fast then serializing through a mutex might be very cheap, and it would make it much easier for the user to write concurrent code.
If this is unnecessary, could you prove it?
E.g. add an example to the examples folder that concurrently fetches 10000 i32
s from a database of type (String, i32)
, increments each i32
, then saves the results back to the database?
As a Rust noob I have no idea how to do that without having 10000 simultaneous connections, and even that approach isn't elegant.
from client-rust.
maybe you could use a mutex here to serialize the writes
Using a mutex in a single threaded scenario would only waste time due to slower atomic instructions. In a multi-threaded scenario, you will not get any concurrency, since a mutex provides mutual exclusion, i.e only one thread will be able to use the connection at a time. If you wanted to share it, on top of that, you'll need to wrap it in an Arc
to make it Send
(since a mutex is !Send
)
from client-rust.
If the writes are fast then serializing through a mutex might be very cheap
Writing to a server over a network cannot be classified as a "fast" operation, especially when you're talking about synchronization
from client-rust.
As a Rust noob I have no idea how to do that without having 10000 simultaneous connections, and even that approach isn't elegant.
You could:
- Pipeline it: if you wanted to use a single thread (so you send 10000 queries over the same connection in one go)
- Use a connection pool: Say spawn it with 10 threads and then send 10K queries over the 10 different connections (edit: reworded to avoid confusion)
from client-rust.
I'll recommend you to read std
's documentation on
- the
sync
module covering when to useMutex
es and other synchronization primitives: https://doc.rust-lang.org/stable/std/sync/index.html. - the
Send
andSync
marker traits
Let me know if you have any other questions :)
from client-rust.
Related Issues (11)
- Error when querying the server HOT 22
- Feature request: Sync API
- Upgrade client to use the Skyhash protocol HOT 2
- Add byte array to Query HOT 2
- Entity/table for connection pooling? HOT 2
- impl FromSkyhashBytes for RawString HOT 1
- Feature: Support streaming versions of LSKEYS (and also "LSVALUES" and "LSPAIRS")
- WhereAmI: Wrong type sent by server HOT 1
- Panic while creating keyspace with next code base HOT 1
- ParseError(ResponseMismatch) when querying binary data HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from client-rust.