GithubHelp home page GithubHelp logo

Comments (4)

zhuxiujia avatar zhuxiujia commented on June 19, 2024

I have implemented a global connection pool in my application using rbatis, structured as follows:

use rbatis::RBatis;
use std::collections::HashMap;
use std::sync::Arc;
use tokio::sync::RwLock;
use lazy_static::lazy_static;

pub struct DataSourceManager {
    pub data_sources: RwLock<HashMap<String, Arc<RBatis>>>,
}

lazy_static! {
    pub static ref DATA_SOURCE_MANAGER: Arc<RwLock<DataSourceManager>> = Arc::new(RwLock::new(DataSourceManager {
        data_sources: RwLock::new(HashMap::new()),
    }));
}

I'm encountering an issue where query execution experiences significant delays after a period of inactivity. Initial queries and consecutive queries when the application starts up work as expected. However, if there's a lapse in database activity (no queries or operations triggered for some time), subsequent query execution suffers from extended wait times. This seems to occur as if the connection is being re-established or there's some latency in reactivating the connection from the pool.

Questions:

Is this behavior related to how rbatis manages connections in the pool after a period of inactivity? Could it be due to connection timeouts or some kind of connection state reset in rbatis? What would be the recommended approach to ensure consistent query execution times, even after periods of database inactivity? I would appreciate any insights or suggestions on how to address this issue. If there are any best practices or configurations in rbatis for managing connections over extended periods of inactivity, that information would be extremely helpful.

Thank you for your assistance!

The connection pool of rbatis will retrieve the connection in the get function and perform a ping operation on the connection. If the ping fails, it will discard and choose the next connection or rebuild the connection.

from rbatis.

huiali avatar huiali commented on June 19, 2024

Thank you for your prompt response and the explanation regarding how rbatis manages the connection pool.

I understand that rbatis performs a ping operation on connections retrieved from the pool and discards/rebuilds them if the ping fails. However, I am facing a peculiar issue that I hope to get some guidance on.

In my application, a simple single-table query executes in just a few milliseconds during initial and consecutive queries. However, if there's a gap in querying (after some idle time), the same query takes about one minute to execute. This significant delay after a period of inactivity is quite puzzling and seems to be disproportionately long, even considering the need to establish a new connection.

Could you please advise on the following:

Is there a configuration within rbatis that controls how often these ping operations occur or how the pool decides to discard connections?
Are there any best practices or additional configurations I should consider to minimize this delay?
Could this behavior be influenced by any external factors such as database server settings or network issues?
Any further insights or suggestions on how to resolve or mitigate this issue would be greatly appreciated. I'm looking to ensure that query response times remain consistent, even after periods of inactivity.

Thank you once again for your support and assistance.

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 19, 2024

Thank you for your prompt response and the explanation regarding how rbatis manages the connection pool.

I understand that rbatis performs a ping operation on connections retrieved from the pool and discards/rebuilds them if the ping fails. However, I am facing a peculiar issue that I hope to get some guidance on.

In my application, a simple single-table query executes in just a few milliseconds during initial and consecutive queries. However, if there's a gap in querying (after some idle time), the same query takes about one minute to execute. This significant delay after a period of inactivity is quite puzzling and seems to be disproportionately long, even considering the need to establish a new connection.

Could you please advise on the following:

Is there a configuration within rbatis that controls how often these ping operations occur or how the pool decides to discard connections? Are there any best practices or additional configurations I should consider to minimize this delay? Could this behavior be influenced by any external factors such as database server settings or network issues? Any further insights or suggestions on how to resolve or mitigate this issue would be greatly appreciated. I'm looking to ensure that query response times remain consistent, even after periods of inactivity.

Thank you once again for your support and assistance.

What database are you using and have you set a connection timeout for the database?
For example, the default timeout for MySQL should be 8 hours

from rbatis.

zhuxiujia avatar zhuxiujia commented on June 19, 2024

Thank you for your prompt response and the explanation regarding how rbatis manages the connection pool.

I understand that rbatis performs a ping operation on connections retrieved from the pool and discards/rebuilds them if the ping fails. However, I am facing a peculiar issue that I hope to get some guidance on.

In my application, a simple single-table query executes in just a few milliseconds during initial and consecutive queries. However, if there's a gap in querying (after some idle time), the same query takes about one minute to execute. This significant delay after a period of inactivity is quite puzzling and seems to be disproportionately long, even considering the need to establish a new connection.

Could you please advise on the following:

Is there a configuration within rbatis that controls how often these ping operations occur or how the pool decides to discard connections? Are there any best practices or additional configurations I should consider to minimize this delay? Could this behavior be influenced by any external factors such as database server settings or network issues? Any further insights or suggestions on how to resolve or mitigate this issue would be greatly appreciated. I'm looking to ensure that query response times remain consistent, even after periods of inactivity.

Thank you once again for your support and assistance.

What do you use to measure query intervals? If it is a Chrome console, HTTP requests may have caching and latency due to browser issuesใ€‚

But if you switch to Postman, you can see that each request takes a stable amount of time

from rbatis.

Related Issues (20)

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.