28

我正在使用 tmux 在开发模式下运行 Rails 3.2.6。当我使用 tmux 滚动浏览 Rails 服务器的输出缓冲区(使用 rails s 运行)时,服务器冻结并且不处理任何请求。当我退出回滚模式时,服务器再次开始正常工作。

在查看输出缓冲区时,如何设置服务器以继续处理请求?

4

1 回答 1

35

If you want to pause and examine at some particular sequence of log messages while your server continues processing requests, it is probably best to directly view the log files instead; you might use less -R log/development.log.

While a tmux pane is in “copy mode” (the mode used to view a pane’s history), tmux does not read any output from the processes running in the pane’s tty. If the processes continue to write output to the tty, then the OS’s tty buffer will eventually fill. When a program writes to a tty with a full buffer, it causes the process to block so that the buffer does not overflow; this is what causes your server to temporarily stop processing requests.

The timeline looks like this:

  1. You enter copy mode to view some old output.
    tmux stops reading from the tty.
  2. Your Rails server continues to write to the tty as it handles ongoing requests.
    The OS absorbs these writes into a tty buffer of some limited size.
  3. Eventually, the OS tty buffer fills up and causes further writes to the tty to block.
    This is where the Rails server “freezes”; it is stuck waiting for the OS to return from (e.g.) a write(2) call it made to display a log message.
  4. You exit copy mode.
    tmux resumes reading from the tty, draining the buffered output and accepting new output.
于 2013-01-28T19:11:25.543 回答