进行进程间通信 [英] Go Inter-Process Communication
问题描述
负载平衡服务器将与多个应用程序服务器和处理请求进行通信。这些服务器既可以运行在同一台计算机上,也可以运行在网络上。
我已经计算出了网络,但现在我需要找到一种最佳的负载均衡方法,平衡器与本地应用程序服务器进行通信。使用 localhost
-networking看起来远非最佳。
我试图通过<$ c $共享内存c> shmget 和 shmat
系统调用,但没有找到任何工作示例和 syscall $ c $
有人能给我提供一个如何使用这些调用的例子,或者是一个在Go上工作的现实替代方案吗?
Go有一个内置的RPC系统(另一种选择是发送采空区编码数据( http://blog.golang.org/2011/ 03 / gobs-of-data.html )。
您不应该在没有基准测试的情况下关闭本地网络。例如,Chrome为IPC使用命名管道,它们在进程之间传输大量数据(例如渲染的位图):
lockquote
我们的主要内部进程通信原语是命名管道。在
Linux& OS X中,我们使用了socketpair()
- http://www.chromium.org/developers/design-documents/inter-process-communication
如果命名管道足够好,它们可能足够满足您的使用情况。另外,如果你写得很好,你可以开始使用命名管道(因为它很容易),然后如果你发现命名管道的性能不够好(共享内存不容易,不管语言如何),就切换到共享内存。
I'm writing a load balanced server system in Go.
The load balancing server will communicate with several application servers and process requests. These servers can both, be running on the same machine or on the network.
I already figured the networking out but now I need to find an optimal way for the load-balancer to communicate with a local application server. Using localhost
-networking seems far from optimal.
I'm trying to share memory via the shmget
and shmat
system-calls but haven't found any working examples and the syscall
package is also completely undocumented.
Can someone provide me with an example of how to use these calls or a realistic alternative that works on Go for doing IPC?
Go has a built-in RPC system (http://golang.org/pkg/rpc/) for easy communication between Go processes.
Another option is to send gob-encoded data (http://blog.golang.org/2011/03/gobs-of-data.html) via network connection.
You shouldn't dismiss local networking without benchmarking. For example Chrome uses named pipes for IPC and they transfer a lot of data (e.g. rendered bitmaps) between processes:
Our main inter-process communication primitive is the named pipe. On Linux & OS X, we use a socketpair()
-- http://www.chromium.org/developers/design-documents/inter-process-communication
If named pipes are good enough for that, they are probably good enough for your use case. Plus, if you write things well, you could start using named pipes (because it's easy) and then switch to shared memory if you find performance of named pipes not good enough (shared memory is not easy regardless of the language).
这篇关于进行进程间通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!