问题描述

我正在用Go编写负载平衡的服务器系统.

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.

localhost
localhost
shmgetshmatsyscall
shmgetshmatsyscall

有人可以为我提供如何使用这些呼叫的示例,还是可以在Go上进行IPC的可行替代方案?

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具有内置的RPC系统( http://golang.org/pkg/rpc/),以简化Go进程之间的通信.

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.

如果不进行基准测试,则不应关闭本地网络.例如,Chrome使用命名管道进行IPC,并在进程之间传输大量数据(例如渲染的位图):

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:

我们主要的进程间通信原语是命名管道.在 Linux& OS X,我们使用一个socketpair()

Our main inter-process communication primitive is the named pipe. On Linux & OS X, we use a socketpair()

如果命名管道足以满足要求,那么它们可能足以满足您的用例.另外,如果编写得不错,则可以开始使用命名管道(因为很简单),然后如果发现命名管道的性能不够好(无论使用哪种语言,共享内存都不容易),然后切换到共享内存.

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

这篇关于如何在Go中实现进程间通讯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!