传递映射、切片到通道和网络上?

huangapple go评论81阅读模式
英文:

Pass map, slice over channel and over network?

问题

在分布在网络上的通道上传递切片(slice)和映射(map)结构的最佳方法是什么?我需要将应用程序分布在多个EC2实例上,并想知道如何通过Go通道进行通信来实现这一点。

以下是我想要运行的工作流程:

  1. 在一个应用程序中处理数据
  2. 将数据分发到10个副本应用程序中
  3. 每个应用程序在一个单独的EC2实例中完成其工作
  4. 一旦它们全部完成,它们将结果发送回原始程序
  5. 这通过通道发送

请告诉我。谢谢!

英文:

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.

huangapple
  • 本文由 发表于 2014年11月29日 18:33:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/27201256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定