Heroku worker dyno上进程之间的TCP Socket通信 [英] TCP Socket communication between processes on Heroku worker dyno

查看:178
本文介绍了Heroku worker dyno上进程之间的TCP Socket通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我们希望Resque工作人员读取一个队列并将数据发送给另一个进程在同一台测试仪上运行。 其他进程是一种现成的软件,通常使用TCP套接字(端口xyz)来监听命令。它设置为在Resque工作器启动之前作为后台进程运行。



但是,当我们尝试本地连接到该TCP套接字时,我们无处可寻。 p>

设置队列的Rake任务执行以下操作:

  task resque:setupdo 
#首先在后台启动我们的侦听器进程
`./some_process_that_listens_on_port_12345&`

#现在让我们的队列工作准备好,设置Redis后备存储
port = 12345
ENV ['QUEUE'] ='*'
ENV ['PORT'] = port.to_s
Resque.redis = ENV ['REDISTOGO_URL']

#从队列开始工作
WorkerClass.enqueue
结束

这是有效的 - 我们的侦听器进程运行,并且Resque尝试处理排队的任务。但是,Resque作业失败,因为它们无法连接到 localhost:12345 (特别是, Errno :: ECONNREFUSED ) 。



可能Heroku在同一台测试仪上阻塞TCP套接字通信。有没有办法解决这个问题?



我尝试将代码从情境中拿出来,然后在命令行中执行(服务器进程声称它是正确绑定到12345):

  nc localhost 12345 -w 1   


但是这并不能连接。



我们目前正在调查改变客户端/ server代码在两边使用 UNIXSocket ,而不是 TCPSocket ,但因为它是一个现成的作品如果可能的话,我们宁愿避免使用我们自己的分支。

你试过Fifo吗?



http://www.gnu.org/software/libc/manual/html_node/FIFO-Special-Files.html#FIFO-Special-Files


I'd like to know how to communicate between processes on a Heroku worker dyno.

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.

However, when we try to connect locally to that TCP socket, we get nowhere.

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

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).

Possibly, Heroku is blocking TCP socket communication on the same dyno. Is there a way around this?

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

But this does not connect either.

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.

解决方案

Have you tried Fifo?

http://www.gnu.org/software/libc/manual/html_node/FIFO-Special-Files.html#FIFO-Special-Files

这篇关于Heroku worker dyno上进程之间的TCP Socket通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆