Comments (6)
I'm facing the same issue - 100% CPU usage (single core) when awaiting russh::Channel::data
.
In comparison, ssh [email protected] "cat > /dev/null" < /dev/urandom
consumes barely any CPU.
Minimal example:
use async_trait::async_trait;
use russh::client;
use russh::client::Config;
use russh_keys::key;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let addrs = ("10.0.0.123", 22);
let mut session = client::connect(Arc::new(Config::default()), addrs, Client).await?;
let auth_ok = session.authenticate_password("user", "pass").await?;
if !auth_ok {
anyhow::bail!("auth failed");
}
let channel = session.channel_open_session().await?;
channel.exec(true, "cat > /dev/null").await?;
let infinite_data = tokio::io::repeat(b'A');
println!("sending data");
channel.data(infinite_data).await?;
unreachable!();
}
struct Client;
#[async_trait]
impl client::Handler for Client {
type Error = russh::Error;
async fn check_server_key(
&mut self,
_server_public_key: &key::PublicKey,
) -> Result<bool, Self::Error> {
Ok(true)
}
}
(I'm using russh 0.44.0-beta.2
)
Flamegraph: flamegraph.svg.gz
(russh
is highlighted)
I generated the flamegraph using cargo flamegraph --release
. I had to let it run for a few minutes to make the data
method more apparent in the perf data.
I also turned on debuginfo in the release profile:
# Cargo.toml
[profile.release]
debug = true
from russh.
Could you please take a profile of your program to see where it's looping?
from russh.
How can I do that?
from russh.
https://nnethercote.github.io/perf-book/profiling.html
from russh.
Is it enough?
7.79% tokio-runtime-w test_agent [.] memcpy
7.77% tokio-runtime-w test_agent [.] <russh::channels::io::tx::ChannelTx<S> as tokio::io::async_write::AsyncWrite>::poll_write
6.62% tokio-runtime-w test_agent [.] tokio::runtime::scheduler::multi_thread::worker::Context::run
5.77% tokio-runtime-w test_agent [.] tokio::runtime::scheduler::multi_thread::worker::<impl tokio::runtime::scheduler::multi_thread::ha 5.11% tokio-runtime-w test_agent [.] tokio::sync::batch_semaphore::Semaphore::add_permits_locked
4.53% tokio-runtime-w test_agent [.] tokio::sync::mutex::Mutex<T>::lock_owned::{{closure}}
4.52% tokio-runtime-w test_agent [.] <tokio::sync::batch_semaphore::Acquire as core::future::future::Future>::poll
3.76% tokio-runtime-w test_agent [.] __libc_free
3.42% tokio-runtime-w test_agent [.] tokio::runtime::context::with_scheduler
3.16% tokio-runtime-w test_agent [.] __unlock
2.95% tokio-runtime-w test_agent [.] <tokio::io::util::copy::Copy<R,W> as core::future::future::Future>::poll
2.79% tokio-runtime-w test_agent [.] tokio::sync::batch_semaphore::Semaphore::release
2.78% tokio-runtime-w test_agent [.] __lock
2.77% tokio-runtime-w test_agent [.] tokio::runtime::task::state::State::transition_to_running
2.46% tokio-runtime-w test_agent [.] tokio::runtime::scheduler::multi_thread::worker::Context::run_task
2.45% tokio-runtime-w test_agent [.] tokio::runtime::task::state::State::transition_to_idle
2.14% tokio-runtime-w test_agent [.] tokio::runtime::task::waker::wake_by_ref
2.04% tokio-runtime-w test_agent [.] tokio::runtime::task::state::State::ref_dec
1.81% tokio-runtime-w test_agent [.] agent::ssh::SshSession::execute::{{closure}}
1.80% tokio-runtime-w test_agent [.] sccp
1.77% tokio-runtime-w test_agent [.] __libc_malloc_impl
1.70% tokio-runtime-w test_agent [.] tokio::runtime::task::harness::Harness<T,S>::poll
1.59% tokio-runtime-w test_agent [.] tokio::runtime::context::scoped::Scoped<T>::with
1.53% tokio-runtime-w test_agent [.] alloc_slot
1.51% tokio-runtime-w test_agent [.] enframe
1.42% tokio-runtime-w test_agent [.] get_meta
1.30% tokio-runtime-w test_agent [.] tokio::runtime::task::core::Core<T,S>::poll
from russh.
There is also additional context of this problem. Probably root reason is target device.
I trying to execute command which sends ~200KB of data. But for unknown reason it recieves just 40KB and then I met 100% cpu usage on my side and stacked process on device with command (sh -c /cat > /some/file). BUT when I restarted this device problem is gone.
So I can't catch this bug now, but behavior of 100% cpu is bad and can break my app again in the next time (it happened rarely some times before, but I could detect it only yesterday since I have thousands of devices where this command is executing). It should generate some error instead or at least react to timeout
from russh.
Related Issues (20)
- How to serve a basic shell #2 HOT 10
- `decode_pkcs5` does not remove padding HOT 2
- `write_key_v1` writes `ed25519` key incorrectly HOT 1
- Missing ciphers HOT 2
- Blocking API
- russh-config: Opinion: deprecate parse_home() and add crate documentation that it parses an OpenSSH-like format HOT 1
- Incorrect sha2 hash function for ecdh-sha2-nistp{384,521}
- The new `Handler` definition makes it harder to build state machines HOT 2
- Support for SCP protocol
- FEATURE REQUEST: add a Geller Field when ssh
- TryFrom<PrivateKey> for KeyPair: RSA assumes SHA512 HOT 3
- `russh::server::Server::handle_session_error` seems to reference the new client instance rather than the one with the failed session HOT 5
- ERROR - Unsupported key type ssh-rsa HOT 2
- Host key checking is lazy
- Error with CryptoVec
- streamlocal-forward support HOT 3
- Why is String being used for Paths? HOT 1
- Unclear interaction between inactivity timer and server keepalive
- Shutdown ssh server HOT 1
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 russh.