zhangxiao
V2EX  ›  问与答

用Tornado能异步操作文件系统IO么?

  •  
  •   zhangxiao · Sep 26, 2012 · 4636 views
    This topic created in 5038 days ago, the information mentioned may be changed or developed.
    我想用tornado处理本地磁盘的git repo,但是不知道怎么异步完成文件系统的读写,主要是读。
    4 replies    1970-01-01 08:00:00 +08:00
    clowwindy
        1
    clowwindy  
       Sep 26, 2012   ❤️ 1
    推荐读一下 http://www.remlab.net/op/nonblock.shtml

    Regular files are always readable and they are also always writeable. This is clearly stated in the relevant POSIX specifications. I cannot stress this enough. Putting a regular file in non-blocking has ABSOLUTELY no effects other than changing one bit in the file flags.
    zhangxiao
        2
    zhangxiao  
    OP
       Sep 26, 2012
    @clowwindy 我刚刚读了一下,但是还有疑问,想确认一下我的理解:
    按照文章作者的意思,磁盘读写也是会出现忙碌的,也会造成用户能感觉到的延时甚至卡死。但是使用non-blocking也不会有任何帮助。
    只有尝试建立一个单独的线程去处理这个文件的读写,才能避免主线程被阻塞。

    如果上述理解是对的,那么nodejs里的对文件的异步IO又是怎么实现的?
    phuslu
        3
    phuslu  
       Sep 26, 2012
    torndao不能,gevent差强人意(gevent 1.0引入的fileobject)
    nodejs不错(libeio)

    值得关注的还有libaio
    clowwindy
        4
    clowwindy  
       Sep 26, 2012
    @zhangxiao 线程或者 aio。磁盘读写不像网络连接,不需要并行化,每个磁盘一个线程,控制队列长度就可以了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3274 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 11:21 · PVG 19:21 · LAX 04:21 · JFK 07:21
    ♥ Do have faith in what you're doing.