英文:
Pass map, slice over channel and over network?
问题
在分布在网络上的通道上传递切片(slice)和映射(map)结构的最佳方法是什么?我需要将应用程序分布在多个EC2
实例上,并想知道如何通过Go
通道进行通信来实现这一点。
以下是我想要运行的工作流程:
- 在一个应用程序中处理数据
- 将数据分发到10个副本应用程序中
- 每个应用程序在一个单独的EC2实例中完成其工作
- 一旦它们全部完成,它们将结果发送回原始程序
- 这通过通道发送
请告诉我。谢谢!
英文:
What is the best way to pass slice and map structure over channel that is distributed over network? I need to distribute the application running over several EC2
instances and wonder how I can achieve this by communicating each application by Go
channel.
Here's the workflow that I would like to run:
1. Process data in one application
2. Distribute the data into 10 replica applications
3. Each 10 application does its job in a separate EC2 instance
4. Once they are all done, they send the result back to the original program
5. This is sent over the channel
Please let me know. Thanks!
答案1
得分: 1
如果取决于你选择的序列化格式。
一个非常适合网络通信的格式是MessagePack(一种高效的二进制序列化格式)。它可以在多种语言之间交换数据,就像JSON一样。但是它更快速和更小巧。
像philhofer/msgp
这样的Go库可以序列化任何结构体(例如带有映射的结构体),包括复合类型(如映射和数组)。
然而,它使用了Go1.4的go generate
命令(go 1.4rc1已经发布)。
从那里开始,像docker/libchan
这样的库可以提供帮助:Libchan是一个超轻量级的网络库,它使网络服务能够以与goroutine使用通道进行通信的方式进行通信。
英文:
If depends on the format you will chose for the serialization.
One well-suited for over-the-network communication is MessagePack (an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller)
A Go library like philhofer/msgp
can serializaze any struct (like one with a map), including composite types like maps and arrays.
However, it uses Go1.4 go generate
command. (go 1.4rc1 is already out)
From there, a library like docker/libchan
can help: Libchan is an ultra-lightweight networking library which lets network services communicate in the same way that goroutines communicate using channels.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论