Heroku worker dyno 上的进程之间的 TCP 套接字通信 [英] TCP Socket communication between processes on Heroku worker dyno
问题描述
我想知道如何在 Heroku worker dyno 上的进程之间进行通信.
I'd like to know how to communicate between processes on a Heroku worker dyno.
我们希望 Resque 工作者读取队列并将数据发送到运行在同一 dyno 上的另一个进程.其他进程"是现成的软件,通常使用 TCP 套接字(端口 xyz)来侦听命令.它被设置为在 Resque Worker 启动之前作为后台进程运行.
We want a Resque worker to read off a queue and send the data to another process running on the same dyno. The "other process" is an off-the-shelf piece of software that usually uses TCP sockets (port xyz) to listen for commands. It is set up to run as a background process before the Resque worker starts.
然而,当我们尝试在本地连接到该 TCP 套接字时,我们一无所获.
However, when we try to connect locally to that TCP socket, we get nowhere.
我们用于设置队列的 Rake 任务是这样做的:
Our Rake task for setting up the queue does this:
task "resque:setup" do
# First launch our listener process in the background
`./some_process_that_listens_on_port_12345 &`
# Now get our queue worker ready, set up Redis backing store
port = 12345
ENV['QUEUE'] = '*'
ENV['PORT'] = port.to_s
Resque.redis = ENV['REDISTOGO_URL']
# Start working from the queue
WorkerClass.enqueue
end
这很有效——我们的侦听器进程运行,而 Resque 尝试处理排队的任务.但是,Resque 作业失败,因为它们无法连接到 localhost:12345
(特别是 Errno::ECONNREFUSED
).
And that works -- our listener process runs, and Resque tries to process queued tasks. However, the Resque jobs fail because they can't connect to localhost:12345
(specifically, Errno::ECONNREFUSED
).
可能是 Heroku 在同一个 dyno 上阻塞了 TCP 套接字通信.有没有办法解决这个问题?
Possibly, Heroku is blocking TCP socket communication on the same dyno. Is there a way around this?
我试图将代码"从情况中取出,直接在命令行上执行(在服务器进程声称它正确绑定到 12345 之后):
I tried to take the "code" out of the situation and just executed on the command line (after the server process claims that it is properly bound to 12345):
nc localhost 12345 -w 1 </dev/null
但这也无法连接.
我们目前正在研究更改客户端/服务器代码以在双方使用 UNIXSocket
而不是 TCPSocket
,但因为它是现成的软件,如果可能的话,我们宁愿避免使用自己的叉子.
We are currently investigating changing the client/server code to use UNIXSocket
on both sides as opposed to TCPSocket
, but as it's an off-the-shelf piece of software, we'd rather avoid our own fork if possible.
推荐答案
您是否尝试过 Fifo?
Have you tried Fifo?
http://www.gnu.org/software/libc/manual/html_node/FIFO-Special-Files.html#FIFO-Special-Files
这篇关于Heroku worker dyno 上的进程之间的 TCP 套接字通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!