Merge pull request #5718 from geekpi/master

translated
This commit is contained in:
geekpi 2017-06-23 08:48:57 +08:00 committed by GitHub
commit 8c46c764ff
2 changed files with 110 additions and 113 deletions

View File

@ -1,113 +0,0 @@
translating----geekpi
[One Year Using Go][18]
============================================================
![](https://bugfender.com/wp-content/uploads/2017/03/one-year-using-go-social-1.jpg)
Our ventures into [Go][5] all started as an internal experiment at [Mobile Jazz][6]. As the company name hints, we develop mobile apps.
After releasing an app into the wild, we soon realised we were missing a tool to check what was actually happening to users and how they were interacting with the app something that would have been very handy in the case of any issues or bugs being reported.
There were a couple of tools around which claimed to help developers in this area, but none of them quite hit the mark, so we decided to build our own. We started by creating a basic set of scripts that quickly evolved into a fully-fledged tool known today as [Bugfender][7]!
As this was initially an experiment, we decided to try out a new trending technology. A love of learning and continual education is a key aspect of Mobile Jazzs core values, so we decided to build it using Go; a relatively new programming language developed by Google. Its a new player in the game and there have been many respected developers saying great things about it.
One year later and the experiment has turned into a startup, weve got an incredible tool thats already helping thousands of developers all over the world. Our servers are processing over 200GB of data everyday incoming from more than 7 million devices.
After using Go for a year, wed like to share some of our thoughts and experiences from taking our small experiment to a production server handling millions and millions of logs.
### Go Ecosystem
No one in the company had any previous experience using Go. Bugfender was our first dive into the language.
Learning the basics was pretty straight forward. Our previous experiences with C/C++/Java/Objective-C/PHP enabled us to learn Go quickly and get developing in days. There were, of course, a few new and unusual things to learn, including GOPATH and how to deal with packages, but that was expected.
Within a few days, we realized that even being a simplified language by design, Go was extremely powerful. It was able to do everything a modern programming language should: being able to work with JSON, communicate between servers and even access databases with no problems (and with just a few lines of code at that).
When building a server, you should first decide if youre going to use any third party libraries or frameworks. For Bugfender, we decided to use:
### Martini
[Martini][8] is a powerful web framework for Go. At the time we started the experiment, it was a great solution and to this day, we havent experienced any problems with it. However if we were to start this experiment again today, we would choose a different framework as Martini is no longer maintained.
Weve further experimented with [Iris][9] (our current favorite) and [Gin][10]. Gin is the successor to Martini and migrating to this will enable us to reuse our existing code.
In the past year, weve realized that Gos standard libraries are really powerful and that you dont really need to rely on a heavy web framework to build a server. It is better to use high-performance libraries that specialize in specific tasks.
~~Iris is our current ~~favourite~~ and in the future, well re-write our servers to use it instead of Martini/Gin, but its not a priority right now.~~
**Edit:** After some discussions about Iris in differents places, we realized that Iris might not be the best option. If we ever decide to re-write our web components, we might look into other options, we are open to suggestions.
### Gorm
Some people are fans of ORM and others are not. We decided to use ORM and more specifically, [GORM][11]. Our implementation was for the web frontend only, keeping it optimized with hand-written SQL for the log ingestion API. In the beginning, we were really happy, but as time progresses, weve started to find problems and we are soon going to remove it completely from our code and use a lower level approach using a standard SQL library with [sqlx][12].
One of the main problems with GORM is Gos ecosystem. As a new language, there have been many new versions since we started developing the product. Some changes in these new releases are not backwards compatible and so, to use the newest library versions we are frequently rewriting existing code and checking hacks we may have created to solve version issues.
These two libraries are the main building blocks of almost any web server, so its important to make a good choice because it can be difficult to change later and will affect your server performance.
### Third-Party Services
Another important area to consider when creating a real world product is the availability of libraries, third-party services and tools. Here, Go is still lacking maturity, most companies dont yet provide a Go library, so you may need to rely on libraries written by other people where quality isnt always guaranteed.
For example, there are great libraries for using [Redis][13] and [ElasticSearch][14], but libraries for other services such as Mixpanel or Stripe are not so good.
Our recommendation before using Go is to check beforehand if theres a good library available for any specific products you may need.
Weve also experienced a lot of problems with Gos package management system. The way it handles versions is far from optimal and over the past year, we have run into various problems getting different versions of the same library between different team members. Recently, however, this problem has been almost solved thanks to the new Go feature that supports vendor packages, alongside the [gopkg.in][15] service.
### Developer Tools
![](https://bugfender.com/wp-content/uploads/2017/03/go-ide.jpg)
As Go is a relatively new language, you might find the developer tools available are not so great when compared to other established languages like Java. When we started Bugfender it was really hard to use any IDE, none seemed to support Go. But in this last year, this has improved a lot with the introduction of [IntelliJ][16] and [Visual Studio Code Go][17] plugins.
Finally looking at other Go tools, the debugger is not-so-great and the profiler is even worse, so debugging your code or trying to optimize it can be hard at times.
### Heading for Production
This is definitely one of the best things about Go, if you want to deploy something to production you just need to build your binary and send it to the server, no dependencies, no need to install extra software, you only need to be able to run a binary file in your server.
If youre used to dealing with other languages where you require a package manager or need to be careful with a language interpreter you may use, Go is a pleasure to work with.
We are also really happy with Gos stability as the servers never seem to crash. We faced a problem some time ago sending big amounts of data to Go Routines but since then weve rarely seen any crashes. Note: if you need to send a lot of data to a Go Routine, youll need to be careful as you can have a heap overflow.
If youre interested in performance, we cannot compare to other languages as we have started with Go from scratch, but given the amount of data we process, we feel its performance is very good, we definitely wouldnt be able to process the same number of requests using PHP so easily.
### Conclusions
Over the year weve had our ups and downs regarding Go. At the beginning we were excited, but after the experiment converted to a real product we started unveiling problems. Weve thought several times about a complete rewrite in Java, but here we are, still working with Go, and in this past year the ecosystem has had some great improvements that simplified our work.
If you want to build your product using Go, you can be sure it will work, but you need to be really careful with one thing: the availability of developers to hire. There are only a few senior Go developers in Silicon Valley, and finding one elsewhere can be a very difficult task.
--------------------------------------------------------------------------------
via: https://bugfender.com/one-year-using-go
作者:[ALEIX VENTAYOL][a]
译者:[译者ID](https://github.com/译者ID)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://bugfender.com/author/aleixventayol
[1]:https://bugfender.com/#facebook
[2]:https://bugfender.com/#twitter
[3]:https://bugfender.com/#google_plus
[4]:https://www.addtoany.com/share#url=https%3A%2F%2Fbugfender.com%2Fone-year-using-go&title=One%20Year%20Using%20Go
[5]:https://golang.org/
[6]:http://mobilejazz.com/
[7]:https://www.bugfender.com/
[8]:https://github.com/go-martini/martini
[9]:https://github.com/kataras/iris
[10]:https://github.com/gin-gonic/gin
[11]:https://github.com/jinzhu/gorm
[12]:https://github.com/jmoiron/sqlx
[13]:https://github.com/go-redis/redis
[14]:https://github.com/olivere/elastic
[15]:http://labix.org/gopkg.in
[16]:https://plugins.jetbrains.com/plugin/5047-go
[17]:https://github.com/Microsoft/vscode-go
[18]:https://bugfender.com/one-year-using-go

View File

@ -0,0 +1,110 @@
[Go 使用一周年][18]
============================================================
![](https://bugfender.com/wp-content/uploads/2017/03/one-year-using-go-social-1.jpg)
我们在 [Mobile Jazz][6] 的一个内部项目开始使用 [Go][5]。如公司名暗示的那样,我们开发移动应用。
在发布一个应用给公众后,我们很快意识到我们缺失一个工具来检查用户实际发生的情况以及他们是如何与应用交互的 - 如果有任何问题后者 bug 报告,这将会相当方便。
现在有几款工具声称能在这个方面帮助开发者,但是没有一个能完全满足要求,因此我们决定自己构建。我们开始创建一组基础的脚本,如今它很快进化成了完整的工具,称为 [Bugfender][7]
由于这最初是一个实验,我们决定使用一种新的趋势技术。对学习以及持续教育的热爱是 Mobile Jazz 的核心价值的重要方面之一,因此我们决定使用 Go 构建。这是一个由 Google 开发的相对新的编程语言。它是游戏中的新玩家,已经有许多受尊敬的开发者对它称赞。
一年后,实验变成了一个启动项目,我们拥有了一个已经帮助了来自全世界的数以千计的开发者的令人难以置信的工具。我们的服务器每天处理来自 700 万台设备的超过 200GB 的数据。
在使用 Go 一年之后,我们想要分享我们将一个小的实验变成处理百万日志的生产服务器的一些想法和经验。
### Go 生态系统
公司中没有人有使用 Go 的经验。Bugfender 是我们第一次深入这个语言。
学习基本相当直接。我们之前在 C/C++/Java/Objective-C/PHP 的经验让我们学习 Go 相当快,并且在几天内就开始开发。当然会有一些新的还有不常见的东西需要学习,包括 GOPATH 还有如何处理包,但这在预期内。
几天之内我们意识到即使是一个简化设计的语言Go 是非常强大的。它能够做任何现代编程语言应该能做的事:能够处理 JSON、服务器之间通讯甚至访问数据库也没问题并且只需要几行代码
在构建一个服务器时,你应该首先决定是否使用任何第三方库或者框架。对于 Bugfender我们决定使用
### Martini
[Martini][8] 是一个强大的 Go web 框架。我们开始这个实验时,它是一个很棒的解决方案,至今也是,我们还没遇到任何问题。然而如果我们如今再次开始这个实验,我们会选择一个不同的框架,因为 Martini 不在被维护了。
我们还试验了 [Iris][9](我们目前的最爱)还有 [Gin][10]。Gin 是 Martini 继任者,并且迁移到这上能让我们重用已有的代码。
在过去的一年中,我们意识到 Go 的标准库是非常强大的,你不必依靠一个臃肿的 web 框架来构建一个服务器。最好在特定任务上使用专门的高性能库。
~~Iris 是我们目前 ~~最喜欢的~~ 并且将来我们将使用它重写服务来替代 Martini/Gin但这目前并不优先。
**编辑:** 在不同地方讨论 Iris 之后,我们意识到 Iris 或许不是最好的选择。如果我们决定重写我们的 web 组件,我们或许会研究其他的选择,我们对提议开放。
### Gorm
一些人是 ORM 的粉丝,一些人不是。我们决定使用 ORM更确切地说是 [GORM][11]。我们的实现只针对 web 前端,对于日志提取 API 仍然保持使用手写优化的 SQL。在一开始我们确实很高兴但是随着时间的推移我们开始发现问题并且我们很快将它从代码中完全移除并且使用 [sqlx][12] 这个标准 SQL 库。
GORM 的一个主要问题是 Go 的生态系统。作为一个新语言,自我们开始开发产品以来已经有很多新版本。在这些新版本中的一些改变并不向后兼容,因此要使用最新库版本,我们要经常重新已有代码并检查我们为解决版本问题做的 hack。
这两个库是大多数 web 服务的主要组件,因此做一个好的选择很重要,因为将来更改会很困难,并且会影响你服务器的性能。
### 第三方服务
在创建一个真实世界产品的另外一个重要方面是考虑库、第三方服务和工具的可用性。在这方面Go 还缺乏成熟度,大多数公司还没有提供 Go 库,因此你或许需要依赖其他人写的质量不能总是保证的库。
比如,对于使用 [Redis][13] 和 [ElasticSearch][14] 有很好的库,但是对于其他服务比如 Mixpanel 或者 Stripe 还没有好的。
我们建议在使用 Go 之前事先检查对于你需要的产品是否有好的库可用。
我们在 Go 的包管理系统上也遇到了很多问题。它处理版本的方式远没有达到最好,并且在过去的一年中,我们在不同的团队成员之间获取到同一个库的不同版本上遇到了很多问题。然而,最近要归功于 Go 新支持的 vendor 包特性,除了 [gopkg.in][15] 服务外,这个问题基本被解决了。
### 开发者工具
![](https://bugfender.com/wp-content/uploads/2017/03/go-ide.jpg)
由于 Go 是一门相对新的语言,你或许发现相比其他成熟的语言像 Java它可用的开发工具并不很好。当我们开始 Bugfender 时,使用任何 IDE 都很困难,似乎没有 IDE 支持 Go。但是在过去的一年中随着 [IntelliJ][16] 和 [Visual Studio Code Go][17] 插件的引入,这一切提高了很多。
最后看下其他的 Go 工具,调试器并不很好并且分析器甚至更糟,因此有时调试你的代码或者尝试优化它会很困难。
### 前往生产
这确实是 Go 最好的东西之一,如果你想要部署一些东西到生产环境中,你只需要构建你的二进制并发送到服务器中,没有依赖,不需要安装额外的软件,你只需要能在服务器中运行进制文件。
如果你习惯于处理那些需要包管理器或者需要小心你使用的语言解释器的语言,用 Go 工作会很高兴。
我们对 Go 的稳定性也很满意,因为服务器似乎从没有崩溃过。我们在发送大量数据给 Go Routines 时遇到过一个问题,但是我们几乎没见到任何崩溃。注意:如果你需要发送大量数据给 Go Routine你需要小心堆溢出。
如果你对性能感兴趣,我们不能与其他语言比较,因为我们从零开始使用 Go但是对于我们处理的数据量我们感觉性能是非常好的我们绝对不能如此轻松地使用 PHP 处理同等数量的请求。
### 总结
在过去的一年中,我们对 Go 有起起伏伏。最初我们是兴奋的,但是在实验变成真实的产品后我们开始揭露问题。我们几次考虑过用 Java 完全重写,但是目前为止,仍旧使用的是 Go并且过去的一年中生态已经有了很大的提升这简化了我们的工作。
如果你想要使用 Go 构建你的产品,你可以保证这可以工作,但是你确实需要小心一件事:可以雇佣的开发者。硅谷中只有很少的高级 Go 开发者,并且在其他地方寻找也是一件非常困难的任务。
--------------------------------------------------------------------------------
via: https://bugfender.com/one-year-using-go
作者:[ALEIX VENTAYOL][a]
译者:[geekpi](https://github.com/geekpi)
校对:[校对者ID](https://github.com/校对者ID)
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
[a]:https://bugfender.com/author/aleixventayol
[1]:https://bugfender.com/#facebook
[2]:https://bugfender.com/#twitter
[3]:https://bugfender.com/#google_plus
[4]:https://www.addtoany.com/share#url=https%3A%2F%2Fbugfender.com%2Fone-year-using-go&title=One%20Year%20Using%20Go
[5]:https://golang.org/
[6]:http://mobilejazz.com/
[7]:https://www.bugfender.com/
[8]:https://github.com/go-martini/martini
[9]:https://github.com/kataras/iris
[10]:https://github.com/gin-gonic/gin
[11]:https://github.com/jinzhu/gorm
[12]:https://github.com/jmoiron/sqlx
[13]:https://github.com/go-redis/redis
[14]:https://github.com/olivere/elastic
[15]:http://labix.org/gopkg.in
[16]:https://plugins.jetbrains.com/plugin/5047-go
[17]:https://github.com/Microsoft/vscode-go
[18]:https://bugfender.com/one-year-using-go