并发写入日志文件 Sinatra、Rack、Thin
我们编写了一个 Sinatra 应用程序,它使用 Thin 作为其 Web 服务器,并使用rack 作为两者之间的中间件。我想知道 Rack 是否足够智能,允许并发写入日志文件(如 config.ru 中定义),而无需任何额外配置。
We have written an Sinatra application that uses Thin as its web server and rack as the middleware between the two. I would like to know if Rack is smart enough to allow concurrent writing to the log file (as defined in the config.ru) without any additional configuration.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我对这个特定的实现没有任何经验,但我猜不会,因为这更多的是写入文件时的并发问题,而不是 Rack 特有的问题。原因是操作系统通常需要锁定文件才能写入它。我想像第一个需要写入日志文件的进程会阻塞其他进程,直到它完成写入,然后后续进程才能写入。
有关其他信息,请查看此处对与 EventMachine 相关的问题的回答。另请参阅维基百科上的文件锁定。
I do not have any experience with this specific implementation, but I'm going to guess no since this is more a problem of concurrency when writing to a file then a problem specifically with Rack. The reason for this is that the Operating System typically needs to lock a file to write to it. I would imagine the first process that needed to write to the log file would block other processes until it finished writing and then subsequent processes would be able to write.
For other information check out this answer to a question related to EventMachine here. Also check out File Locking on wikipedia.