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

Old performance issues, new plan of action ? #22

Open
swatgoss opened this issue Feb 2, 2019 · 11 comments
Open

Old performance issues, new plan of action ? #22

swatgoss opened this issue Feb 2, 2019 · 11 comments

Comments

@swatgoss
Copy link

swatgoss commented Feb 2, 2019

Hi,

I've been using XBMC and Kodi for quite a long time and i'm sure im not the only one interested and affected by the old performances issues on SFTP remote sources.

As a personnal example, i frequently use a dedicated server that can push a little over 1Gbps on internet (filezilla, python simpleHTTPserver, nginx, rsync ...) to a client fiber that is also capable of receiving 1Gbps.
Also the ping -seen on the client side- between the client and the dedicated server is typically around 13-16ms.

And when im browsing a BIG SFTP folder through Kodi (17.6, not tested 18.0 until now) on my Kodi "dedicated laptop" (win10 pro, i5 520m,, 8GB RAM and 1Gbps RJ45 network), Windows Task Manager network graph does not go over 8Mbps !

I think im not alone with this kind of problems -https://trac.kodi.tv/ticket/14038- (very low performance/usage relative to real capacity of the network and computers involved), there were numerous topics about HPN-SSH implementation for example ...

Now that there is an addon (independent of main app source code), could it be thinkable to look into solution for those kind of inefficiencies ?
Or if the problems are already resolved, it would be a good -public- place to make it known loud and clear !

@aluo-x
Copy link

aluo-x commented Mar 30, 2022

Performance on the latest Matrix 19.4 is still quite poor, I'm barely breaking 30MB/s on a 1Gbps capable network. On the same system using SSHFS-Win the speeds reach 90MB/s.

@aluo-x
Copy link

aluo-x commented Mar 30, 2022

Tagging @AlwinEsch, not sure if there is any low hanging fruit in terms of optimization? I'm on Windows 10.

@KyleSanderson
Copy link

This is dog slow on a new firestick, and two other amlogic boxes. Running sshfs independently worked around the bug on those other boxes, but this is completely unusable on Android.

@wonx
Copy link

wonx commented Jul 26, 2022

I can confirm this issue. On a 300mbps capable network, sftp transfer within kodi reaches 5-8mbps at most, nit enough to play HD videos. However, if I mount a folder using sshfs externally, the performance is more than 10 times faster. Sadly, on Android devices like a firetv stick, there's no option to externally add a sftp mountpoint.

@sand-bit
Copy link

Yeah, the sftp performance is pretty poor :(

@seanmikhaels
Copy link

Same issue on 20.2 using the VFS plugin. Not able to achieve anything over 20 megabits/s. Vanilla SSHFS using Debian on the same hardware target/ yields over 300 Megabits.

@KyleSanderson
Copy link

There's no prefetching which is the problem. They're not using the async API, and the video buffering code is just terrible.

so; latency + low throughput = bad news. It's very stupid and silly, but if you stream over http it'll improve the situation. The devs on a Shield use the native SMB functionality to the OS to work around the bug.

@arnova
Copy link
Member

arnova commented Oct 19, 2023

There's no prefetching which is the problem. They're not using the async API, and the video buffering code is just terrible.

so; latency + low throughput = bad news. It's very stupid and silly, but if you stream over http it'll improve the situation. The devs on a Shield use the native SMB functionality to the OS to work around the bug.

Why is the video buffering code "terrible" ? There's no argument to back that statement up (and I think it's not true either). It seems to work pretty well with other protocols, right?

@seanmikhaels
Copy link

There's no prefetching which is the problem. They're not using the async API, and the video buffering code is just terrible.
so; latency + low throughput = bad news. It's very stupid and silly, but if you stream over http it'll improve the situation. The devs on a Shield use the native SMB functionality to the OS to work around the bug.

Why is the video buffering code "terrible" ? There's no argument to back that statement up (and I think it's not true either). It seems to work pretty well with other protocols, right?

Agreed here, does not seem to be effecting other protocols. UPNP, SMB, work seamlessly. HTTPS is an option, but when you're streaming over the internet, SSH is just such an easy and versatile protocol you can do so many things over a single port. Wonder what the effort would be to fix this.

@KyleSanderson
Copy link

There's no prefetching which is the problem. They're not using the async API, and the video buffering code is just terrible.
so; latency + low throughput = bad news. It's very stupid and silly, but if you stream over http it'll improve the situation. The devs on a Shield use the native SMB functionality to the OS to work around the bug.

Why is the video buffering code "terrible" ? There's no argument to back that statement up (and I think it's not true either). It seems to work pretty well with other protocols, right?

Agreed here, does not seem to be effecting other protocols. UPNP, SMB, work seamlessly. HTTPS is an option, but when you're streaming over the internet, SSH is just such an easy and versatile protocol you can do so many things over a single port. Wonder what the effort would be to fix this.

Very small, just change the call-sites to async_read. Directory prefetching and caching will help with library import.

There's no prefetching which is the problem. They're not using the async API, and the video buffering code is just terrible.
so; latency + low throughput = bad news. It's very stupid and silly, but if you stream over http it'll improve the situation. The devs on a Shield use the native SMB functionality to the OS to work around the bug.

Why is the video buffering code "terrible" ? There's no argument to back that statement up (and I think it's not true either). It seems to work pretty well with other protocols, right?

xbmc/xbmc#22799
xbmc/xbmc#22952
xbmc/xbmc#21408
xbmc/xbmc#22834

Not really sure where the breakdown here is.

@Mynacol
Copy link

Mynacol commented May 9, 2024

I face the same issue, limiting download speeds (max. 30 Mbit/s) for links with ~20ms round trip time so I dug into it.
This add-on essentially passes through the read call to libssh, which answers it blocking and synchronously. This means if Kodi requests a chunk of data, the request is passed to libssh -> the server and finally after the reply is received back to kodi. This means for each chunk one round trip time is spent waiting.

IDK if Kodi tries to use multiple threads, but this add-on uses a mutex on all reads, preventing such optimizations. Libssh says you shouldn't share sessions for thread safety, so this synchronization might be required. PR #114 tried to address this problem.

Besides this point I have two optimization ideas: 1. Increase the chunk size by implementing GetChunkSize to reduce the impact of the latency delay. The default seems to be 128KB. 2. Asynchronously read data. As Kodi doesn't seem to offer a native interface, we could add preloading in the add-on or use an even simpler approach: On each Read call (except the first) return the already preloaded chunk and start a new preload with sftp_async_read_begin(). This way the libssh library effectively preloads the next chunk before it is requested by Kodi. Care must be taken regarding the internal modification of the current offset and again thread safety.

Mynacol added a commit to Mynacol/vfs.sftp that referenced this issue Jul 1, 2024
To improve the performance. The current implementation severely
underperforms, reaching at maximum 60 Mbit/s on a local 1 Gbit/s link
(where the cmd tool `scp` performs at over 800 Mbit/s). With video bit rates
reaching 60 Mbit/s, videos can no longer be streamed without occasional
interruptions.
This problem severely worsens if the network latency is higher. One
situation with about 40 ms RTT latency only reached about 10 Mbit/s,
even though the network could handle more throughput.
See xbmc#22 for more discussion.

This work always initiates the next read at the end of each previous one.
This however requires to specify a length, which might not match with
the length Kodi requests next (e.g. at the end of file). To avoid
memory leaks, we have to call `sftp_async_read` with a valid buffer of
the correct size. This means a temporary buffer is needed.
If too much was actually read, this work simply rewinds the current file
offset to the Kodi-expected place.

This might also mess with other/threaded usage, as the async work can
run concurrently with normally mutexed areas, and even is expected to
change the file position during retrieval, leading to inconsistent
results when calling `GetPosition` at the same time.
Mynacol added a commit to Mynacol/vfs.sftp that referenced this issue Jul 1, 2024
To improve the performance. The current implementation severely
underperforms, reaching at maximum 60 Mbit/s on a local 1 Gbit/s link
(where the cmd tool `scp` performs at over 800 Mbit/s). With video bit rates
reaching 60 Mbit/s, videos can no longer be streamed without occasional
interruptions.
This problem severely worsens if the network latency is higher. One
situation with about 40 ms RTT latency only reached about 10 Mbit/s,
even though the network could handle more throughput.
See xbmc#22 for more discussion.

This work always initiates the next read at the end of each previous one.
This however requires to specify a length, which might not match with
the length Kodi requests next (e.g. at the end of file). To avoid
memory leaks, we have to call `sftp_async_read` with a valid buffer of
the correct size. This means a temporary buffer is needed.
If too much was actually read, this work simply rewinds the current file
offset to the Kodi-expected place.

This might also mess with other/threaded usage, as the async work can
run concurrently with normally mutexed areas, and even is expected to
change the file position during retrieval, leading to inconsistent
results when calling `GetPosition` at the same time.
Mynacol added a commit to Mynacol/vfs.sftp that referenced this issue Jul 1, 2024
To improve the performance. The current implementation severely
underperforms, reaching at maximum 60 Mbit/s on a local 1 Gbit/s link
(where the cmd tool `scp` performs at over 800 Mbit/s). With video bit rates
reaching 60 Mbit/s, videos can no longer be streamed without occasional
interruptions.
This problem severely worsens if the network latency is higher. One
situation with about 40 ms RTT latency only reached about 10 Mbit/s,
even though the network could handle more throughput.
See xbmc#22 for more discussion.

This work always initiates the next read at the end of each previous one.
This however requires to specify a length, which might not match with
the length Kodi requests next (e.g. at the end of file). To avoid
memory leaks, we have to call `sftp_async_read` with a valid buffer of
the correct size. This means a temporary buffer is needed.
If too much was actually read, this work simply rewinds the current file
offset to the Kodi-expected place.

This might also mess with other/threaded usage, as the async work can
run concurrently with normally mutexed areas, and even is expected to
change the file position during retrieval, leading to inconsistent
results when calling `GetPosition` at the same time.
Mynacol added a commit to Mynacol/vfs.sftp that referenced this issue Jul 1, 2024
To improve the performance. The current implementation severely
underperforms, reaching at maximum 60 Mbit/s on a local 1 Gbit/s link
(where the cmd tool `scp` performs at over 800 Mbit/s). With video bit rates
reaching 60 Mbit/s, videos can no longer be streamed without occasional
interruptions.
This problem severely worsens if the network latency is higher. One
situation with about 40 ms RTT latency only reached about 10 Mbit/s,
even though the network could handle more throughput.
See xbmc#22 for more discussion.

This work always initiates the next read at the end of each previous one.
This however requires to specify a length, which might not match with
the length Kodi requests next (e.g. at the end of file). To avoid
memory leaks, we have to call `sftp_async_read` with a valid buffer of
the correct size. This means a temporary buffer is needed.
If too much was actually read, this work simply rewinds the current file
offset to the Kodi-expected place.

This might also mess with other/threaded usage, as the async work can
run concurrently with normally mutexed areas, and even is expected to
change the file position during retrieval, leading to inconsistent
results when calling `GetPosition` at the same time.
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

No branches or pull requests

8 participants