Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Media repository reads files from disk on the main thread. #9312

Open
erikjohnston opened this issue Feb 3, 2021 · 4 comments
Open

Media repository reads files from disk on the main thread. #9312

erikjohnston opened this issue Feb 3, 2021 · 4 comments
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.

Comments

@erikjohnston
Copy link
Member

erikjohnston commented Feb 3, 2021

It does use FileSender, which reads the file in chunks and so shouldn't be too slow, but nonetheless there is potential for disk I/O to take a long time (especially with networked storage).

We should look into either a) doing async file I/O (though that is likely hard) or b) do the reads from a thread.

@erikjohnston erikjohnston changed the title Media repository reads files from dis Media repository reads files from disk on the main thread. Feb 3, 2021
@richvdh
Copy link
Member

richvdh commented Feb 3, 2021

doing async file I/O (though that is likely hard)

it really shouldn't be: twisted already has support for doing async socket I/O: files are no different. Let's not be scared of looking into it, anyway.

@erikjohnston
Copy link
Member Author

In Linux AFAIK setting the open file descriptor to non blocking has no effect for files, I can't really find a good source for that other than random blogs and SO answers https://stackoverflow.com/a/16513897

I believe the three options for doing async file I/O on linux:

  1. Use POSIX AIO interface, which is a glibc thing that works in userspace via thread pools;
  2. Linux AIO, which uses io_submit and the like https://kkourt.io/blog/2017/10-14-linux-aio.html; or
  3. Using the new io_uring interface, which requires a new kernel

@richvdh
Copy link
Member

richvdh commented Feb 4, 2021

ouch. TIL. thanks.

@erikjohnston erikjohnston added the T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks. label Feb 4, 2021
@clokep
Copy link
Member

clokep commented Feb 4, 2021

Using the new io_uring interface, which requires a new kernel

There was an interesting mailing list thread about adding support to this to Twisted: https://twistedmatrix.com/pipermail/twisted-python/2021-January/065382.html

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Task Refactoring, removal, replacement, enabling or disabling functionality, other engineering tasks.
Projects
None yet
Development

No branches or pull requests

3 participants