使用子域的负载平衡/ TCP 端口转发

发布于 2024-12-19 20:14:32 字数 1553 浏览 1 评论 0原文

我正在开发一个项目

1.需要多个进程在唯一端口(可能在多个主机上)监听请求

2.每个进程都旨在为唯一的客户端提供服务

3.客户端应使用 client_id 连接到相应的服务器进程.domainname.com 作为标识符/端点。

前任: 请求到达

client_id_1.domainname.com:FIXED_PORT should go to host_1:port_1
client_id_2.domainname.com:FIXED_PORT should go to host_2:port_2    
etc..
[Edited for clarification : the port number with which client will access should be fixed.Only the client_id would change with change in client]

4.[已编辑(错过了这一点)]。映射需要是动态/可修改的。例如,如果一个进程死掉,则必须启动另一个进程,该进程可能不在同一端口上

我尝试了以下方法(使用java)

1.实现了tcp服务器,并尝试使用tcp使用 http://code.google.com/p/portforward/ 和其他类似的端口转发东西我通过搜索找到的。问题是它使用的 InetAddress 没有请求 uri(使用 uri 中的子域获取客户端 id)

2.在嵌入式 jetty 中将服务器进程作为 Servlet 实现。这仅适用于 GET 请求。 GET 请求可以使用 POST 重定向到特定服务器,

httpServletResonse.sendRedirect("http://host_1:port_1")

我们有 RequestDispatcher,它最终会生成 GET。似乎 HTTP 规范不允许使用 POST 进行重定向。

我还发现了这个 在另一个 Web 应用程序中调用 doPost使用 Req Dispatcher 转发,建议以编程方式自己触发 POST 请求。(我还没有研究过这种方法)

我希望有一个解决方案。 我可能过于简单化了,但我认为这与 HEROKU 所做的类似。它们也有在不同端口上运行的后端进程(dynos)(我对此不确定)。它们与基于应用程序的传入请求相匹配-名称。下面讨论 http://www.quora.com/Scalability/How-does-Heroku-工作,但这个问题没有得到解答。

我已经被困在这个问题上很长一段时间了。我非常感谢您的帮助。

I am working on a project

1.which requires several processes to be listening for requests on unique ports(possibly on multiple hosts)

2.Every process is meant to serve a unique client

3.The clients should connect to there respective server process using client_id.domainname.com as the identifier / end point.

Ex:
requests coming to

client_id_1.domainname.com:FIXED_PORT should go to host_1:port_1
client_id_2.domainname.com:FIXED_PORT should go to host_2:port_2    
etc..
[Edited for clarification : the port number with which client will access should be fixed.Only the client_id would change with change in client]

4.[Edited(had missed this point)]. The mapping needs to be dynamic/modifiable .Example if one the processes die ,another has to be brought up which might not be on the same port

I have tried the following approaches(using java)

1.implemented tcp server,and tried using tcp portforwarding using http://code.google.com/p/portforward/ and other similar stuff that i found by searching.The problem is this uses InetAddress which does not have the request uri(to get the client id using subdomain from uri)

2.implemented server processes as Servlets in embedded jetty.This is fine only for GET requests. GET requests can be redirected to specific server using

httpServletResonse.sendRedirect("http://host_1:port_1")

for POST we have RequestDispatcher which ultimately resuls in a GET.It seems that the HTTP specification doesnt allow a redirect with POST.

I also found this Calling the doPost in another Webapp with a Req Dispatcher forward which suggests to to fire a POST request yourself programmatically.(I havent still worked on this approach yet)

I hope there is a solution for this.
I might be highly oversimplifying, but I think this is similar to what HEROKU does.They also have backend processes(dynos) which run on different ports(i am not sure about this).They are matched with incoming requests based on the app-name.The following discusses
http://www.quora.com/Scalability/How-does-Heroku-work but this question is not answered.

I have been stuck for quite sometime on this.I would be realy thankful for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-12-26 20:14:32

这在 Heroku 堆栈上是不可能的,因为它仅支持标准 HTTP 和 HTTPS 端口(80 和 443)。当您启动进程时,连接服务的端口由 Heroku 基础设施决定(请参阅 $PORT 和过程文件)。

尝试做任何不适合此模型的事情在它们支持更多端口之前都不会真正起作用。

This is not possible on the Heroku stack as it only supports the standard HTTP and HTTPS ports (80 & 443). When you spin up your process the port that the service is connected on is dictated by the Heroku infrastructure (See $PORT and Procfiles).

Trying to do anything that doesn't fit this model is not really going to work until they support more ports.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文