Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High memory consumption after update from 0.16 to 0.18 #1150

Closed
ok-ul-ch opened this issue Jul 12, 2023 · 3 comments · Fixed by #1153
Closed

High memory consumption after update from 0.16 to 0.18 #1150

ok-ul-ch opened this issue Jul 12, 2023 · 3 comments · Fixed by #1153

Comments

@ok-ul-ch
Copy link
Contributor

Summary

After the update to 0.18, we've started to observe weird memory behavior in our app, which looks like a memory leak to me.

I've used code from examples/examples/tokio_console.rs to reproduce the issue, it starts jsonrpsee server, registers dummy method and waits. Client sends requests sequentially and receives 405 Status Code.

Server code
use std::net::SocketAddr;

use jsonrpsee::server::ServerBuilder;
use jsonrpsee::RpcModule;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
	let _ = run_server().await?;

	futures::future::pending().await
}

async fn run_server() -> anyhow::Result<SocketAddr> {
	let server = ServerBuilder::default().build("127.0.0.1:9944").await?;
	let mut module = RpcModule::new(());

	//Use for 0.18
	//module.register_method("say_hello", |_, _| "lo")?;
	module.register_method("say_hello", |_, _| Ok("lo"))?;

	let addr = server.local_addr()?;
	let handle = server.start(module)?;

	// In this example we don't care about doing a stopping the server so let it run forever.
	// You may use the `ServerHandle` to shut it down or manage it yourself.
	tokio::spawn(handle.stopped());

	Ok(addr)
}
Client code
use std::time::Duration;

#[tokio::main]
async fn main() {
    tokio::spawn(async {
        loop {
            let _ = dbg!(reqwest::get("http://127.0.01:9944").await);

            tokio::time::sleep(Duration::from_millis(10)).await
        }
    });

    futures::future::pending().await
}

STR

  1. Run server code sample for both: 0.16.2 and 0.18.2 versions of jsonrpsee;
  2. Run client;
  3. Observe memory usage.

Behavior

0.16.2 - memory usage is constant, as expected. See heaptrack profile report
image

0.18.2 - memory usage grows over time. See heaptrack profile report
image

@ok-ul-ch
Copy link
Contributor Author

It looks like the issue is in the fact that futures running connections are not dropped.
Connections are inserted here and here BUT not removed in the server's loop here

Flamegraph reporting "leak"
image

@aoudiamoncef
Copy link
Contributor

aoudiamoncef commented Jul 12, 2023

Hi @mralexes, have you tested with max_connections = 1 ? (to see the result)

@ok-ul-ch
Copy link
Contributor Author

@aoudiamoncef yup, same behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants