Giter Site home page Giter Site logo

Comments (7)

ohsayan avatar ohsayan commented on June 15, 2024

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 &Ts).

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.

ohsayan avatar ohsayan commented on June 15, 2024

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.

emchristiansen avatar emchristiansen commented on June 15, 2024

You're referring to, e.g., AsyncWrite here?

impl<T: AsyncWrite + Unpin + Send + Sync> WriteQueryAsync<T> for Query {

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 i32s 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.

ohsayan avatar ohsayan commented on June 15, 2024

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.

ohsayan avatar ohsayan commented on June 15, 2024

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.

ohsayan avatar ohsayan commented on June 15, 2024

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.

ohsayan avatar ohsayan commented on June 15, 2024

I'll recommend you to read std's documentation on

Let me know if you have any other questions :)

from client-rust.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.