What GOARCH to set for my webapp written in Go?

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

What GOARCH to set for my webapp written in Go?

问题

我想在DigitalOcean或类似的云服务提供商上部署我的Web应用(基本上是CRUD操作)。我发现我可以设置GOARCH=386GOARCH=amd64。这两个选项在我的电脑上都可以正常构建。

我该如何决定在服务器上部署哪个选项?有最新的Ubuntu、Debian、CentOS等流行选项可供选择。

英文:

I want to deploy my webapp (basically CRUD) on DigitalOcean or a similar cloud provider. I found out that I can set GOARCH=386 or GOARCH=amd64. Both build properly on my computer.

How do I decide which one I need to deploy on server? There are all popular options like latest Ubuntu, Debian, CentOS.

答案1

得分: 2

选择与您的 droplet 架构匹配的版本。您可以在 droplets 列表中查看此信息。请注意,如果针对 386 平台进行编译,您可以在 386amd64 平台上运行它,而如果编译为 amd64,则只能在 amd64 平台上运行。

如果您问应该选择哪个版本,那就取决于您。请知道,某些操作在 amd64 上更快(特别是那些使用/涉及 int64 等 64 位值的操作),而且如果您针对 amd64 架构进行编译,Go 工具的某些功能只能在该架构上使用,例如 race detector支持的系统

race detector 可在 darwin/amd64freebsd/amd64linux/amd64windows/amd64 上运行。

amd64 的可执行二进制文件大小和内存使用量略大,但对于 Go 来说,这并不是真正的问题,因为一个简单运行的 Go Web 服务器只使用大约 8 MB 的内存。当然,如果您使用过度大的数组/切片,例如 [big_number]int,那么问题就会出现,因为在 386 上,int 的大小为 4 字节,而在 amd64 上为 8 字节。

英文:

Set the one that matches the architecture of your droplet. You can view this on your droplets list. Note that targeting the 386 platform you can run it on both 386 and amd64 platforms, while compiling to amd64 you can only run it on amd64.

If you're asking which to choose, then it's up to you. Know that some operations are faster on amd64 (especially those which use / involve 64-bit values like int64), and also some features of the Go tool are only available if you target the amd64 architecture, for example the race detector, Supported Systems:

> The race detector runs on darwin/amd64, freebsd/amd64, linux/amd64, and windows/amd64.

Executable binary size and memory usage is somewhat bigger for amd64, but it's not really an issue in case of Go, as a simple, running Go web server uses like 8 MB of memory. Unless you use excessively large arrays / slices like [big_number]int of course, as the size of int will be 4 bytes on 386 and 8 bytes on amd64.

huangapple
  • 本文由 发表于 2017年1月3日 22:07:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/41445348.html
匿名

发表评论

匿名网友

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

确定