本集简介
双语字幕
仅展示文本字幕,不包含中文音频;想边听边看,请使用 Bayt 播客 App。
我是特拉维斯·里德,欢迎收听Go Time。
I'm Travis Reeder, and this is Go Time.
Go Time是一档每周播出的播客,我们将讨论围绕Go编程语言、社区以及其间所有话题的有趣内容。
It's Go Time, a weekly podcast where we discuss interesting topics around the Go programming language, the community, and everything in between.
如果你目前正在使用Go,或者希望学习Go,那么这档节目非常适合你。
If you currently write Go or aspire to, this is the show for you.
好的。
Okay.
这是第三期节目。
So episode number three.
今天,我们邀请了Brian加入通话。
Today, we have Brian on the call.
我想跟大家打个招呼,Brian。
I wanna tell everybody hello, Brian.
你好。
Hello.
我们这里还有卡莉西亚,像往常一样。
And we also have Carlicia here as usual.
大家好。
Hello, everybody.
今天我们也有一位特别嘉宾,一位资深的Go社区成员,我说的是真正的资深Go社区成员。
And we have a special guest today, a long time Go community member, and I mean long time Go community member.
他有一把很棒的胡子。
He's got a great beard.
他还是iron.io的首席技术官和联合创始人。
And he's also the CTO and cofounder of iron.io.
我们这里还有特拉维斯·里德。
We have Travis Reeder here.
跟大家打个招呼吧,特拉维斯。
Tell everybody hello, Travis.
你好。
Hello.
通常,我们会先聊聊最近看到的一些新闻和文章。
So typically, we start the show off, just talking about some, any news and articles that we've come across.
布莱恩,卡莉·苏,你们有什么要分享的吗?
Brian, Carly Sue, do you have anything?
哦,我有个大消息。
Oh, I got something big.
是的。
Yeah.
我们现在都会关注编译器时间,因为
So, you know, we we all follow compiler times on on tip these days because
编译器?没人会这么做。
the compiler Nobody does that.
是的。
Yeah.
Go 1.6 中编译器速度稍微变慢了一点。
The compiler slowed down a little bit in Go 1.6.
我最近看到戴夫·钱尼发了一条推文,显示最近一次提交大幅缩短了编译时间。
And I saw a tweet from Dave Cheney, recently that showed that one of the most recent commits cut compile times.
我正在看他的Juju图表。
I'm I'm looking at his Juju graph.
在我看来,编译时间减少了大约40%。
It looks to me like it cut it about 40%.
所以我们正越来越接近Go 1.4的编译速度,我们知道这一定会发生,我对此感到非常兴奋。
So we're getting much, much closer back to, go 1.4 compile times, which we knew would happen, and I'm very excited to see.
所以希望当1.7版本发布时,编译慢的问题不会像以前那么严重了。
So hopefully when, 1.7 ships, the the compile pain won't be as as bad as it was before.
这对咱们所有人来说都是一个非常重大的进展。
That's that's a really big event for all of us.
感谢编译器团队的每一位成员。
So thank you for everybody on the compiler team.
罗布·格里泽默,你太棒了。
Rob Griesemer, you rock.
谢谢你们为我们做这些。
Thanks for doing that for us.
我们非常感激。
We appreciate it.
是的。
Yeah.
我认为当他们把编译器转向Go时,这在很大程度上是公开的,因为很多工作都是通过代码生成完成的,我们都知道这种情况会发生。
I think that that was kind of a public thing when they converted to compiler to go because a lot of it was kind of done, through code generation that we all knew that that would happen.
但看到性能恢复回来真是太好了。
But it's great to kinda see the performance come back.
这是1.7的一部分吗?
Is that part of one seven?
这是锁定在1.7版本中的,还是只是一个临时的提交?
Is that locked into that release, or is this just a commit that's kinda hanging?
1.7还没有功能冻结,所以我假设现在在TIP中的任何内容都可能是1.7的候选,除非它导致全面崩溃,否则没有理由不包含它。
There's not a feature freeze for one seven yet, so I'm assuming that anything that's in TIP now is is a candidate for 1.7, and there's no reason it wouldn't be included unless it breaks everything.
我对此感到非常兴奋。
I'm I'm super excited about that.
编译时间,翻倍了吗?
Compile times, what, doubled?
大概是类似的情况。
It it was something along those lines.
至少翻了一倍。
At least doubled.
是的。
Yeah.
它们确实很糟糕。
They they were harsh.
我的意思是,这跟 C 或 C++ 相比还是小巫见大巫,但没错。
I mean, that's still nothing compared to to c or c plus plus but Right.
你知道,我们
You know, we
这还不足以让人讨厌。
wouldn't a reason to hate.
对吧?
Right?
当你原本有闪电般的编译速度,而它只是降到了普通的快速编译时,每个人就开始抱怨了。
When you have lightning fast compile times and they and they go down to just fast compile times, everybody whines.
但好消息是
But but the nice news
还不够快。
about isn't fast enough.
关于最近几个版本的好消息是,虽然编译时间略有增加,但性能确实提升了不少。
The nice news about these last couple releases is that we've had, although compile times went up a bit, you know, performance has improved quite a bit.
通过SSA的改进,我认为Go的整体运行速度正在加快。
So with the SSA changes, I think Go is speeding up in general.
如果我们能把编译时间再降回原来的水平,那在编译器的两个方面我们都能赢。
And if we can get those compile times back down to where they were, we win on both sides, both sides of the compiler.
是的。
Yeah.
同意。
Agreed.
我还有另一个我觉得挺有趣的新闻,但我完全没资格谈论这个。
So I have another news item that I thought was interesting, but I am completely unqualified to talk about.
Cloudflare 发布了一篇博客,讲的是如何构建最简单的 Go 静态分析工具,这让我想到,也许 SSA 这东西我也能搞懂,读起来非常有趣。
There was a Cloudflare blog post about building the simplest go static analysis tool possible and it made me think that you know maybe SSA is something within my reach and it was a very interesting read.
所以,我希望有空的时候能深入研究一下,玩一玩这个。
So I I hope to be able to to dig into that when I have some spare time and and play with that.
但这篇博客确实值得一读。
But it's definitely a good read.
这篇博客文章会放在我们的节目笔记里。
That blog post will be in our show notes.
你们有人用过任何静态分析工具吗?
Have any of you guys played with any static analysis tools?
实际上,我确实玩过一些静态分析工具。
So I actually I mean, I've played with some of the static analysis tools.
静态分析工具。
Static analysis tools.
绕口令。
Tongue twister.
我用过一些已经创建好的工具,但还没自己开发过任何工具。
So I've played with some of the the tooling that's already been created, but I haven't created any of my own.
不过我确实看到了那个 Cloudflare 的帖子。
I did see that Cloudflare post, though.
是的,这确实让这些事情看起来更容易上手了。
And, yeah, that does make things look approachable.
我不确定自己目前有什么特别想写的,但听起来挺有趣的。
I'm not sure that I have anything in particular I want to write yet, but it does sound fun.
New Relic 有一个静态分析工具,对吧?
New Relic has a static analysis tool, correct?
但我不认为它目前还支持 Go 吗?
But I don't think it has support for Go yet?
说实话,
To be
我好久没关注过 New Relic 了。
honest, I haven't looked at New Relic in in a while.
我的意思是,在我用 Ruby 的时候,New Relic 用得很多,但我没用它做过 Go 项目,所以不清楚他们支持得怎么样。
I mean, in in my Ruby days, there was a lot of New Relic, but I don't think I've used it with Go, so I'm not sure what support they have.
使用 Go 的人是不是普遍都不用 New Relic?
Is it a general thing that people who are using Go are not using New Relic?
我很好奇。
I wonder.
我觉得他们最近才增加了对 Go 的一些支持。
I think they just recently added some Go support.
不过我不清楚支持程度如何。
I don't know how much, though.
在Ruby时代,这确实很流行。
That was certainly popular in the Ruby days.
当然了。
That's for sure.
没错。
It was.
是啊。
Yeah.
每个人都用New Relic。
Every everybody had New Relic.
每个人。
Everybody.
没错。
Exactly.
我们今天早上其实也聊到过这一点,因为我们知道iron.io以前是个Ruby公司。
So we were actually talking about that, a little bit this morning, because we know that iron.io was a Ruby shop prior.
还有多少 Ruby 代码保留着?
How much Ruby is still left?
还有一些零零散散的 Ruby 代码还在使用。
So there are still some bits and pieces that are in Ruby.
通常是那些不需要高性能、我们只是还没来得及迁移的部分。
Typically, the things that don't need to perform really, really well, and we've just kinda haven't ported them yet.
说实话,我仍然是 Ruby 的粉丝。
And to be honest, I'm still a Ruby fan.
如果我要写一些不需要高性能、也不会被很多人使用的东西,我还是会偶尔选择 Ruby。
If if I'm writing something that doesn't need to perform and won't be used by a lot of people, I'll but, you know, I'll still reach for Ruby sometimes.
所以
So
我也会跟别人这么说。
I tell people that too.
我觉得 Ruby 在我心中仍然有特殊的地位。
Ruby, I think, still has a special place in my heart.
是啊。
Yeah.
你知道的?
It's you know?
我超爱它那种阅读起来的感觉,还有类似的东西。
I I love I love the way it reads and stuff like that.
而且,对于快速搭建简单的CRUD应用,简直无可匹敌。
So and, mean, for throwing together quick crud apps, I mean, you can't beat it.
我的意思是,我可以用Rails在周末内快速搭出一个管理后台。
I mean, I can take Rails and I can throw together like an admin area in a weekend.
你知道的?
You know?
嗯。
Mhmm.
所以,尤其是在原型设计方面。
So and so especially for prototyping.
尽管我觉得现在 React 和 JSON API 在构建快速应用方面的生产力已经接近我过去用 Rails 开发时的感受。
And although I think these days, React and just the JSON API has has come pretty close to the productivity that I used to feel with Rails throwing together credit apps.
对。
Right.
是的。
Yes.
我认为当你在写 Ruby 和 Ruby on Rails 时,我还在用,但当项目规模变大后,就会变得棘手,不知道该怎么处理了。
I think when you're writing Ruby and Ruby on Rails, I do it still, and it starts becoming problematic when it just grows and then you don't know what to do with it.
考虑采用微服务,把那些需要更高性能的部分迁移到其他技术中,可能是一个值得尝试的方向。
It's starting to think about microservices maybe moving parts of your app that need to be more performant into other technologies can be a worthwhile endeavor.
如今我对 Ruby 的看法,和我对 Java 的看法非常相似。
You know, my thought on Ruby these days is pretty similar to my thought on Java.
并不是我不喜欢这些语言。
It it's not that I don't like the languages.
我不喜欢的是人们编写这些语言的方式。
I don't like the way people write the language.
嗯。
Mhmm.
你知道的?
You know?
就像,Ruby 和 Rails 确实很棒,但人们只是因为能轻易地把它们堆在一起,就搞出这些庞大、紧密耦合的系统,结果变得很难维护。
Like, it's like Ruby and Rails have been great, but these huge monolithic coupled together things because people just throw it together because they can, then it becomes hard to support.
是的。
Yeah.
没错。
Yeah.
你刚才问的这个问题,埃里克,可能让我想起了上周我们一直在讨论的问题:我们是否衡量性能,是否为性能做优化。
And this question that you asked, Eric, maybe reminded me of the question that we were throwing around last week about whether we measure performance, whether we optimise for performance.
我认为特拉维斯应该是这方面的专家。
And I think Travis should be the most expert here.
我在想,特拉维斯,你是如何为未来所需的性能负载做规划的?
I am wondering, Travis, how do you plan for performance loads that you will need in the future?
在规划时,有多少前期工作是用于预判这个部分未来需要如何执行的?
How much pre planning goes into identifying this piece will need to be performed in the future?
因为很多时候我们会说:我不需要更高效的技术,因为我的应用永远不需要那么高的性能。
Because I think a lot of times we go about saying, Well, I don't need this more efficient technology because my app is never going to need that much performance.
另一方面,有时候你事先就知道,但有时候你并不知道,必须事后才弄清楚。
And on the other hand, sometimes you know beforehand, but sometimes you don't know and you need to figure it out.
是的。
Yeah.
所以,嗯,这种情况是怎么发生的?
So, yeah, how does that go?
我的意思是,这根本无法预测。
I mean, it's it's impossible to predict.
对吧?
Right?
我的意思是,我们当初根本不知道需要什么,这就是为什么我们从 Ruby 转到了 Go。
I mean, we didn't know what what we would need up front, which is why, you know, we went from Ruby and had to switch to Go.
但如今,当我们对所需有了更好的了解时,我们总是试图突破极限。
But nowadays, when we we do have a better idea of what we need and and we just always try to push the limit.
最近,我们的博客 iron.com 上发布了一篇博文。
There was a recent blog post on our on our blog dot iron.
内容是关于在 IronMQ 上实现每秒百万条消息的。
About, getting a million messages per second on IronMQ.
所以,你知道,我们正在不断突破。
So, you know, we're pushing it.
我们目前没有客户达到这种速度,但我们努力追求这样的里程碑。
We we we have no customers that are doing that kind of speed, but we try to push and hit kind of milestones like that.
所以,如果客户真的需要,或者我们总是领先于客户的需求。
So, you know, if a customer does need that or we're always ahead of what our customers would need.
而且这很酷。
Plus it's just cool.
而且很酷。
And it's cool.
是的。
Yeah.
当你得到那些逗号时,真的很酷。
It's cool when you get those commas.
是的。
Yeah.
没有什么比好的基准测试更让我们高兴的了。
Nothing makes us happier than good benchmarks.
是的。
Yeah.
没错。
Exactly.
对。
Yes.
但那不仅仅是Go。
But but that wasn't just Go.
我的意思是,我们很多东西都归因于我们选择的数据库以及底层技术。
I mean, we had to we a lot of that is due to the database we chose and, like, the the underlying technologies.
我们实际上在底层使用了RocksDB。
We're actually using RoxtDB under the hood.
Rocks是一种非常有趣的技术。
Rocks is a really interesting technology.
Rocks太棒了。
Rocks is awesome.
CockroachDB也是基于RocksDB构建的。
And CockroachDB is written on top of RocksDB too.
它基本上实现了Google Spanner论文中的一些内容,再结合其他一些技术,但这些全都是用Go写的,而它们的文件系统层则是用RocksDB实现的。
It basically is implementing some of Google Spanners paper, mixed with some other stuff, but that's all in Go, and then their file system layer is done with Roxyb.
是的。
Yeah.
是的。
Yeah.
我们真的很喜欢Cockroach这个项目。
We're pretty I like that cockroach project.
我不太清楚它现在进展到什么程度了。
I don't I don't know where it's at now.
上次我查看的时候,它还处于很早期的阶段。
It was pretty early, you know, the last time I checked.
但我们为IronMQ做了类似的事情。
But, we basically did the same thing for IronMQ.
我们把Rocks作为持久化层,速度非常快。
We took rocks as the persistence layer, which is super fast.
对于队列来说也很合适,因为所有数据都是有序的,结果非常好。
It's nice for a queue too because all the data is sorted, but kinda worked out really nice.
然后我们不得不在Rocks之上构建网络、复制、故障转移和扩展功能。
And then we had to build the networking and replication and failover and scaling on top of rocks, basically.
那你们最终用Raft作为共识协议了吗?
Now did you end up using Raft for your consensus protocol?
没有。
No.
我其实没有参与这个升级的item q团队,但我们正在使用某种东西,我相信是Raft。
I I wasn't really on the item q team in this kind of upgrade, but we are using something, and I believe it is Raft.
而且没人愿意去实现其他的。
And nobody wants to implement the other ones.
是的。
Yeah.
是的。
Yeah.
是的。
Yeah.
我记得第一次看到Raft论文时的情景。
I remember the first time I saw the Raft paper.
我当时想:就10页?
I was like, 10 pages?
就这样?
That's it?
不是。
No.
这个分布式共识协议就这么简单?
This can't be right for a distributed consensus protocol?
是的。
Yeah.
因为论文的副标题是‘凡人的共识’。
Because the subtitle of the paper, Consensus for Mortals.
对。
Right.
是的。
Yeah.
没错。
That's right.
标题大概是那样的,对吧?
The title was something like that, wasn't it?
好吧。
Alright.
所以,我想咱们来聊聊一些有趣的 Go 项目吧。
So, I guess let's let's talk about some interesting, Go projects.
Brian 有个习惯,他睡觉前会下载所有有趣的 Go 相关 GitHub 项目,然后第二天早上一股脑儿全发给我。
So Brian has this whole thing where he goes to sleep and he downloads, all the interesting git, git GitHub projects for Go, and then he just spews them out to me in the morning.
这就是我今晚入睡的方式——浏览 Go 项目的最新提交。
It's how I get myself to sleep tonight, browsing the latest commits to Go projects.
我希望他先筛选过一遍,因为我没那么多时间。
And and I hope that he curates it first because I don't have that kind of time.
我有。
I do.
我只分享那些有趣的项目。
I I only share the interesting ones.
今天第一个项目,我几个月前看到的时候还处于初期阶段,但现在看起来已经相当不错了。
The first one today, I saw a couple months ago and it was just in its its beginnings, but it it looks like it's getting pretty nice.
有一个由Richard Knop编写的OAuth 2.0服务器。
There's a an OAuth two server written by Richard Knop.
它叫go-oauth2-server,从功能上看已经越来越成熟了。
It's called go dash o auth two dash server, and it looks like it's getting pretty solid in terms of its capabilities.
这是一个独立的服务器。
So it's a a standalone server.
它使用etcd进行配置,我认为使用PostgreSQL进行数据存储。
It's backed by etcd for configuration and I think Postgres for, data storage.
它为你的应用提供完整的OAuth 2.0流程,并生成密钥等全套功能。
And it gives you the full OAuth two flows for your apps and, generates keys, the whole works.
所以这看起来是一个非常值得一看的项目。
So it it looks like something that's well worth checking out.
当然,相关链接会在节目笔记中提供。
Links to that, of course, will be in the show notes.
它的文档非常出色。
It has wonderful documentation.
确实如此。
It does.
真的吗?
Really.
太棒了。
That's amazing.
在所有
Of the
我见过的OAuth服务器中最好的。
best I've ever seen for an OAuth server.
我同意。
I agree.
对于一个OAuth服务器来说。
For an OAuth server.
你知道吗,蟑螂这个项目,也是我见过的文档最好的项目之一。
You know, of, cockroach again, that is probably one of the best documented projects I've ever seen too.
哦,同意。
Oh, agreed.
是的。
Yeah.
那个,真漂亮。
That one, beautiful.
文档做得太好了。
Just so well documented.
而且那个 C++ 代码也很美观。
And and the c plus plus code was pretty too.
我从没见过 C++ 能写成这样。
I don't think I've ever seen c plus plus look like that.
可读性很强?
Readable?
这是什么奇怪的语言?
What what is this weird language?
哦,等等。
Oh, wait.
这是C++?
This is c plus plus?
这真的是C++?
It's really c plus plus?
好吧。
Alright.
几周前我偶然发现了第二个项目,同样地,它已经变得非常有趣了,那就是RQ Lite,一个分布式SQLite。
The second project I stumbled across a couple weeks ago, and again, it's to the point where it's starting to look really interesting, that's RQ Lite, which is the distributed SQLite.
是的。
Yeah.
我也一直在等它。
Was waiting on it too.
亚当迟早会告诉我们,它不是你所说的SQLite
Adam's gonna tell us at some point that it's not you say SQLite
你的发音不对。
at the You're not pronouncing it right.
是S Q
It's s q
S S Q l i t e。
s s q lite.
不管它到底怎么读。
Well, whatever it is.
RQ Lite是支持Raft协议的SQLite版本,它让你能够拥有一个分布式SQLite数据库。
RQ lite is the Raft enabled version of SQLite, and it allows you to have, a distributed SQLite database.
而且它完全是用Go语言构建的,是分布式的,非常酷的东西。
And that's all built in Go, it's distributed, pretty slick stuff.
它看起来会非常高性能,所以我真的很想测试一下。
It it looks like it would be really high performance, so I'm I'm kinda itching to test that one out.
我可能得搭建一个小集群,看看我能做什么
I might have to build a little cluster and see what I can
那个接口是他们把它变成了HTTP,而不是直接使用真正的SQLite适配器吗?
interface for that is that they turned it into HTTP rather than interacting with, like, an actual SQLite adapter?
其实两种方式都可以。
Both, actually.
你可以直接查询磁盘上的SQLite数据库。
You can query directly against the SQLite DB on disk.
而我认为,你必须通过HTTP API来执行所有的数据更改,这实际上只是发送DDL语句。
And you I think you're required to do all of your, data changes over the HTTP API, which actually just sends, DDL.
所以这个API只是一个非常小巧的DDL JSON包装器。
So the the API is is a really tiny JSON wrapper for DDL.
所以缺点就是你不能直接使用普通的SQLite适配器。
So the downside is just that you can't just use a normal SQLite adapter.
你得开发一个HTTP客户端来存储你的数据。
You'd you'd kinda have to develop, you know, HTTP client to store your data.
不过,这确实很有趣,因为像 Raft、etcd 和 Consul 这样的技术真正让人们更容易构建自己的分布式系统,而且正如特拉维斯提到的,它们在 RocksDB 的基础上构建了持久化层,并利用图结构来实现内部的分布式共识。
Still, I mean, it's really interesting though, because things like Raft and etcd and console have like really enabled people to build their own distributed systems much more easily and just, you know, kind of to Travis's point too, you know, they've they've built on top of RocksDB for the persistence layer and leveraged graph, you know, for doing their own distributed census internally.
所以你可以自己设计数据库。
So you can kind of make up your own databases.
我的意思不是说建议每个人都这么做,但是
I mean, not that you'd suggest everybody do that, but
Facebook 就用 MongoDB 这么做过。
Facebook did it with MongoDB.
他们把 MongoDB 拿来,底下塞进 RocksDB,打造了一个极其快速、容错且高性能的数据库系统。
They took, Mongo and and stuffed rocks underneath it and have an extremely fast and fault tolerant and high performance, database system.
我想是查莉·梅杰斯 setup 的吗?
I think is it Charity Majors that that had set up?
我记不太清了。
I can't remember.
但不管怎样,大家都在这么做,这很酷。
But, anyway, it's it's everybody's doing it, and it's cool.
有人试过用 Rocks 作为 Manga 的后端吗?
Anyone tried that rocks back end for manga?
我没有。
I have not.
没有。
No.
它曾经在我列表上,是的。
It it was on my list and yeah.
它
It
它还在那儿。
It's still there.
不过现在 Parse 都死了,不知道这个是不是也死了。
Wonder if it's dead, though, now that Parse is dead.
这是个好问题。
That's a good question.
那个让我上瘾的另一个是什么来着,布莱恩?
What was the other one that I I got hooked on, Brian?
那个被重写成C++的Cassandra。
The Cassandra one that was rewritten in c plus plus.
那个叫什么名字来着?
What was the name of that?
哦,我现在想不起来了。
Oh, I can't remember now.
我等节目结束之后就会想起来的。
I'll I'll think of it, you know, right after we end the show.
但不管怎样,特拉维斯,如果你还没看过的话,它基本上和Cassandra是线兼容的,只不过用的是C++而不是Java。
But, anyway, Travis, if you haven't seen it, it's basically, wire compatible with Cassandra, but written in c plus plus instead of Java.
哦,哇。
Oh, wow.
对。
Yeah.
这真的很酷。
That was really cool.
数据库是埃里克的鸦片。
Databases are Eric's crack.
他根本停不下来。
He can't put it down.
对布莱恩来说是代码生成,对埃里克来说是数据库。
It's code generation for Brian and databases for Eric.
你应该看看这些年布莱恩和我看过哪些数据库。
You should see the list of databases Brian and I have looked at over the years.
我的意思是,各种各样的时序数据库、用GPU编写的数据库,什么都有。
I mean, different time series databases, databases that are written on the GPU, just all kinds of stuff.
我还是想亲眼看看其中一个能运行起来。
I still wanna see one of those work.
现在关于GPU的数据库 hype 太多了,但我还没见过谁真正发布了一个能实际做事的。
There's so many hype databases right now for GPU, but I haven't seen anybody release one that actually does anything.
等待时间是多久?
What was the wait?
GPU数据库。
GPU DB.
GPU数据库。
GPU DB.
还有另一个。
And there was another one.
还有另一个。
There's another one.
但据我所知,它们两者都差不多是虚无缥缈的概念。
But they're at least from what I can tell, they both seem to be pretty close to vaporware.
直到有人听到这期节目,并用它做出一些真正酷的东西。
And until somebody hears this episode and does something really cool with it.
是的。
Yeah.
我在等着。
I'm waiting.
我的邮箱是 bkettleson@gmail.com。
My email address is bkettleson@gmail.com.
给我发封邮件,证明一下真有人在用 GPU 数据库做点什么。
Send me an email and prove to me that somebody's doing something with GPU databases.
我没亲眼看到就不信。
I don't believe it until I see it.
好吧。
Alright.
那我们还聊点什么?
So what else do we have?
最后一个有趣的 Go 项目是个老项目,但我最近才开始用,发现它作为工具简直太棒了,那就是 SyncThing。
So the last interesting Go project is an old one, but one that I just started using recently and found it to be about as awesome as a utility can be, and that's SyncThing.
他们的网站是 syncthing.net。
So their website is syncthing.net.
如果你熟悉任何一种点对点同步工具,比如 BitTorrent Sync,那它就是类似的东西,但这是一个开放协议。
And if you're familiar with, you know, any one of the, peer to peer syncing tools like BitTorrent sync, it's the same sort of thing, but it's it's an open protocol.
它是用 Go 语言编写的。
It's written in Go.
从实用角度来看,它非常适合在你的 Mac 和 Linux 机器之间,或者笔记本电脑和台式机之间同步文档文件夹。
And, it's from a utility perspective, it's great to just, you know, sync your documents folder between your Mac and your Linux machine or or your laptop and your desktop.
我大概是两周前开始试用的。
I tried it this last I guess it's been two weeks now.
我一直在我 Mac 和 Linux 系统之间同步我的 GoPath 源代码目录。
I've been syncing my GoPath source directory between my Mac and my Linux box.
我把它设置为大约二十秒同步一次。
And I have it set to, like, a twenty second sync repeat.
所以,如果我在楼下时在 Mac 上保存了一个文件,等二十秒后合上盖子,再回到楼上打开 Linux 机器,只需启动 VIM,就能继续编辑同一个文件并看到更改内容。
So that if, if I make a if I save a file on my Mac while I'm sitting downstairs, and give it twenty seconds, close the lid, I can come back upstairs onto the Linux box and keep editing that same file with the changes, just by opening VIM up.
这真的让我感到无比自由。
And it's it's been liberating.
这太神奇了。
It's pretty amazing.
我没想到同步速度会快到足以实现这一点。
I didn't realize that, a, the the synchronization was quick enough to be able to enable that.
我以前从未想过,我可以同步我的 GoPath,至少是它的源代码目录,而且不会有任何问题。
And it had just never occurred to me before that I could synchronize my my GoPath, at least the source directory of it, and not have any repercussions.
它一点都没有给我带来麻烦。
It hasn't bitten me in in any way.
这真的很棒。
It's been really cool.
你把某个项目 git clone 到我的 GoPath 里,下次我在 Linux 机器上时,它就直接在那里了。
You git clone something into my GoPath, and next time I'm on my Linux machine, it's just there.
这真的很棒。
It's really cool.
你现在在用这个
Now you're using this
你是在用这个代替 Dropbox 吗?
you're using this in place of, say, Dropbox?
嗯,这太
Well, it's so
这不是集中式存储,而是点对点存储。
it's not it's not centralized storage, it's peer to peer storage.
所以,好吧。
So Okay.
每个每个
Each each
每台计算机都运行自己的守护进程,它们通过一个中心化的分布式哈希表进行通信,帮助各台计算机相互定位。
computer runs its own daemon, and they communicate with a centralized, distributed hash table sort of thing that that helps each of the computers locate each other.
但你需要客户端授权,这样没人能随便登录并获取我的源代码目录。
But you have to have a client authorization, so nobody could just log in and and grab my source directory.
你必须启用各个客户端之间的通信。
You have to enable each of the different clients to talk to each other.
所以这里面涉及相当多的安全措施,而且没有像Dropbox那样的中心化存储。
So there's there's a good amount of security involved in it, and there is no no central storage like Dropbox.
所以它和Dropbox并不完全一样,但如果你有两台机器,完全可以用来实现同样的功能。
So it's not quite the same as Dropbox, although you could easily use it for the same same capabilities if you had two machines.
它能在广域网上运行吗?
And it works over the WAN?
可以。
It does.
它在任何地方都能用。
It works anywhere.
我不清楚他们用了什么技术,但我从未遇到过NAT穿透之类的问题。
It I don't know what technologies they're using, but I haven't run into any, NAT piercing problems or anything like that.
它就是能正常工作。
It just it just works.
我正在想,有没有其他方式可以实现这个功能,因为我想要把代码仓库放到Dropbox之类的地方。
I'm trying to think of, the alternative to alternative way to do this as far as writing codes, because I wanna put a repo on Dropbox or something like that.
但这种方式的替代方案是不断推送到中央仓库,然后在你的另一台机器上拉取。
But the alternative to this, the way you're doing this, would be to push to the central repo all the time and then pull it on your on your other machine.
这非常方便。
And, this is super handy.
确实如此。
It really is.
很流畅。
It's slick.
它大大减少了我不得不推送的混乱分支数量,因为只要我还没准备好将某些内容提交到仓库,只要它保存在我的磁盘上,就会同步到另一台电脑,我就没问题。
Cut down the number of crazy branches I've had to push to drastically because if I'm not ready to commit something to a repository, as long as it's saved on my disk, it's synced to another computer and and I'm good.
所以我真的很喜欢这个工作流程。
So I'm I'm really enjoying the workflow.
我可能在做些不该做的事,但我并不在意,因为到目前为止还没出过问题,而且太棒了。
I'm probably doing something I shouldn't be doing, but I don't care because it hasn't bitten me yet, and it's awesome.
Syncthing.net。
Syncthing.net.
展开剩余字幕(还有 480 条)
好的。
Alright.
那我们继续吧,顺便让特拉维斯也参与一下。
So let's move on and, rope Travis in here a little bit.
既然他也在节目中,我们最好跟他聊一聊。
Being he's on the show, we should probably talk to him a little bit.
那么,特拉维斯,你最近有没有看到什么让你感兴趣的新项目?无论是Go相关的还是工具类的?
Well, Travis, did did you have any interesting projects that you've you've seen recently that kinda piqued your interest, whether they're Go related or utilities?
有。
Yeah.
我最近一直在关注的一个项目是CADdy,c-a-d-d-y。
I mean, one that I've been looking at pretty closely is CADdy, c a d d y.
它是一个网页服务器兼
It's like a web server slash
嗯。
Yeah.
由
Written by a
内置了 Let's Encrypt 等功能。
with Let's Encrypt built in and things like that.
看起来很酷。
Seems pretty cool.
我还没机会真正使用它,但我非常感兴趣,因为我们需要一个代理层。
I haven't had a chance to really, really use it, but I'm very interested in it because well, because we have a want or a need to have a some kind of proxy layer.
所以我们肯定会考虑它。
So we're we're looking at that for sure.
是的。
Yeah.
我可以告诉你,Gopher Academy、Gopher Academy 博客和 Gopher Con 的所有网站都自四月起就运行在 Caddy 之后,那时它还处于最早期的发布版本,我们非常喜欢它。
Well, I can tell you that all of the Gopher Academy and the Gopher Academy blog and Gopher Con websites are all served behind CADI and have been since something like April when it was in its earliest possible releases and we absolutely love it.
使用 Caddy 简直再方便不过了。
Couldn't be easier to use Caddy.
是的。
Yeah.
是的。
Yeah.
布莱恩大力推荐。
Brian went all Huge thumbs up.
布莱恩就像你们当初对Go那样,全力投入测试版。
Brian went all super beta on it just like you guys did with Go.
他说,能编译通过。
He's like, it compiles.
我就直接部署了。
I'm deploying it.
是的。
Yeah.
很不错。
It's nice.
嗯。
Yeah.
我们,我唯一希望的是它能更具可编程性。
We, the the only thing I I was kinda hoping it would be more programmatic.
我当时想试着把所有内部功能都整合进来,用在一个不错的界面里。
I was trying to sort of be able to pull in all the internals and use it, you know, in a nice interface.
现在看来它更像是一个网页服务器驱动的系统,你需要配置文件之类的。
It seems like it's very it's more web server driven at this point where you need a you need the config file and whatnot.
我原本希望可以动态地添加很多东西,也能移除一些功能。
I was I was hoping to be able to add add a whole bunch stuff and take away things kind of dynamically.
我知道马特一直在努力让它可以嵌入使用。
I know Matt has been working a lot on making it embeddable.
我认为现在可以了。
I think it is now.
我知道他们一直在抽象出一些组件,因为凯宾。
I know they've been abstracting out some of the components because me Ki Bin.
Ki Bin。
Ki Bin.
他正在开发核心DNS,这是一个借鉴了Caddy中许多他非常喜欢的概念的DNS服务器。
He's working on core DNS, which is like a DNS server that's taking a lot of concepts from Caddy that he really liked.
因此,已经进行了一些抽象,以便复用部分逻辑。
So there's been some abstractions made to reuse some of that logic.
是的。
Yeah.
所以如果你最近没看过,建议你再看一下,因为我很确定它现在可以嵌入了。
So if you haven't looked at it recently, you might wanna take a a look at it again and check it out because I'm I'm pretty positive it's embedded now.
是的。
Yeah.
实际上。
There was actually.
我刚才其实正在和Matt聊。
I was actually talking to it's Matt.
对吧?
Right?
马特·霍尔特?
Matt Holt?
马特。
Matt.
嗯。
Yeah.
对。
Yeah.
而我当时想找的那些部分,比如代理和后端之类的东西,还没有实现编程化。
And, the part the pieces that I was looking for, like, proxy and back ends and stuff like that wasn't wasn't programmatic yet.
你基本上得生成一个配置文件,然后重启它之类的。
You had to basically generate a config file and then restart it kinda thing.
哦。
Oh.
但是
But
我猜它最终会实现的。
I imagine it'll get there.
我只要在Matt耳边轻声一说,一两天内它就会出现在Caddy里。
All I have to do is whisper it in Matt's ear, and in a day or two, it's gonna show up in caddy.
所以
So
酷。
Cool.
嗯,希望真的能实现。
Well, hopefully, it does.
那大概是几周前的事了,我想。
That was probably that was a couple weeks ago, I think.
也许你们也可以悄悄说一下,这样会更快实现。
Maybe you guys can whisper it too, and it'll happen faster.
另一个我不觉得特别激动人心,但最近很喜欢的是 Viper。
Another one that, you know, it doesn't it's not too exciting, but I've been really liking is Viper.
它基本上是一些命令行工具,用于读取环境变量和配置文件。
It's basically, like, command line tools and pulling in environment variables and config files.
并让它们相互覆盖,这样就能默认回退到一个合理的值。
And override kinda one with the other so that it defaults back to something sane.
是的。
Yeah.
是的。
Yeah.
所以我们现在到处都在用它。
So we've been using that all over the place now.
它已经差不多成了默认选择。
It's kinda become a default.
这真的很好。
That's really good.
你试过 Viper 的远程配置吗?
Have you tried the, remote configuration for Viper yet?
我没有。
I have not.
没有。
No.
我想我是去年添加的。
I added that, I think, last year.
我超爱 Viper。
I I love Viper.
我觉得它真的很棒。
I think it's really awesome.
所以我们把远程配置作为基础配置。
So we used, the remote config as the baseline configuration.
也就是说,每台机器、每个应用都需要知道的内容都来自 etcd。
So, you know, things that every machine, every app needs to know comes from etcd.
然后你可以在其基础上叠加额外的内容,效果非常好。
And then you can just layer on extra stuff on top of that, and it worked out really nicely.
哦,这很酷。
Oh, that's cool.
是的。
Yeah.
在我了解Go语言并开始学习之前,我从未写过任何命令行工具。
I wanted to mention that I had never written any command line tool before I found out about Go and started learning Go.
我觉得有了Cobra和Viper,这简直太棒了。
And I think it's just amazing, the coolest day in having Cobra and Viper.
如果人们,如果你还没试过,你一定会上瘾的。
If people, if you haven't tried it, you're going to get addicted to it.
是的。
Yeah.
我觉得所有这些都源自Steve的更大项目——Hugo。
I think all of those came out of Steve's bigger project, is Hugo.
是的。
Yes.
所以我认为他把这些从那个项目中抽象出来,是因为人们有类似的需求。
So I think he abstracted those out of that because people had kind of similar needs.
而且,是的,我的确很喜欢这些东西,比如 Viper 支持子命令之类的功能。
And, yeah, I mean, I I love some of that stuff like, Viper with, being able to do the subcommands and things like that.
当你有一个命令行工具,功能多到必须隐藏起来时,这样做就方便多了。
So much easier when you have some command line utility that just has just a crap ton of functionality you have to hide away.
能够使用子命令真好,Micro 让你可以很好地组织这些功能。
It's nice to just be able to do the subcommands, and Micro allows you to kind of really organize it nicely.
是的。
Yeah.
这些仓库都在 github.com/spf13/cobra/viper/hugo/pflag。
Those those repos are at github.com/spf13/cobra/viper/hugo/pflag.
这里有
There's I
我知道,像史蒂夫这么高产的人恐怕没人能比了。
I know that think there is anybody as prolific as as Steve out there.
没有。
No.
那也是很不错的东西。
That that's good stuff too.
有趣的是,我曾跟好几个开发命令行应用的项目交流过,他们最初都没用任何命令行库,后来却转向了其他工具,最终大家都选择了 Cobra,因为它是编写命令行应用最友好的接口。
And and it's funny because I've I've talked to several projects that were written writing command line apps, and they've started with, no command line enabling libraries, and then they move to something else, and everybody ends up on COBRA because it's just the nicest interface for writing command line apps.
所以,如果你要写一个 Go 语言的命令行应用,别绕弯子了,直接用 Cobra 吧,因为每个人都是这么做的。
So if you're gonna write a Go command line app, skip all the craziness and just go straight to COBRA because that's what everybody else does.
没错。
Yep.
你在这档播客里能听到一堆免费的建议。
You get all these free opinions on this podcast.
那
The
我再推荐一个我觉得相当不错的项目。
value I'm throw I'm gonna throw one more project that I, I think is pretty pretty good.
它是JIN Web框架,嗯。
It's the, JIN web framework Mhmm.
或者说是API框架。
Or API framework.
在我看来,这是我到目前为止在Go语言中找到的最好的框架。
I think it seems to me it's the best one for Go so far that I've found.
这能去掉大量代码,让一切变得简单多了。
This makes it gets rid of so much code, makes makes everything so much easier.
是的。
Yeah.
而且保持了代码的可读性。
And keeps it readable.
这才是关键。
That's that's the trick.
在开发大型 Web 应用时,你不能牺牲可读性。
You can't you can't lose readability when you're writing those big web apps.
Jin 在这方面做得不错。
And and Jin does a good job.
我同意。
I agree.
是的。
Yeah.
我觉得我曾经用过几乎所有的框架,但我就是无法决定。
I've I think I've been through almost all of them at one point or another, and I can't I can't decide.
每个框架都有我喜欢的地方,也有我讨厌的地方。
It's just there's things I love about each, and there's things I hate about each.
我觉得我会永远讨厌 Web 框架。
And I feel like I'm going to hate web frameworks forever.
嗯,你知道的,我对于代码生成的痴迷让我必须成为 Goa 的粉丝。
Well, you know, my my, code generation fetish means that I have to be a a Goa fan.
所以对于我来说,做网页应用就只用Goa,别无选择。
So it's it's Goa for me and nothing else in terms of web apps.
所以我得趁机宣传一下Goa。
So I I had to get that plug in there.
我得公平地说。
And I have to be fair.
尽管布莱恩一直努力让我接受,但我还没真正用过Goa。
As much as Brian tries to beat it into me, I have yet to play with Goa.
总有一天。
One day.
嘿。
Hey.
我也说过同样的话。
I said the same thing.
我花了多久才让你转用Vim的?
How long did it take me to convert you to, Vim?
好几年。
Years.
但自从用了之后,我就再也没回头了,所以你也得相信我,Goa真的不错。
But now I've I haven't looked back, so I think you need to trust me on Goa too.
嗯,总有一天吧,你知道的,等我有大把空闲时间的时候。
Well, one of these days, you know, when I when I have a ton of free time.
对吧?
Right?
没错。
Exactly.
就是这样,特拉维斯。
There you go, Travis.
你得试试Goa,然后告诉我们你的感受。
You need to try Goa, and then you let us know.
好的。
Okay.
我来把它拿出去。
I'll take it out.
你可以作为客观的第三方。
You can be the objective third party.
回来告诉我们你对代码生成和API开发的看法。
Come back and tell us what you think about code generation and what when it comes to API development.
我们会让你上节目,然后你告诉我们你的想法。
We'll we'll put you on the show and and you can tell us what you think.
对于特拉维斯和所有还不熟悉Goa的听众来说,简单说,这其实是一种用于描述API的DSL,然后它会生成实际的实现代码——布赖恩可能更能说清楚,但它的核心就是用DSL来描述API,再自动生成代码。
And for Travis and for anybody listening who's not already familiar with, Goa, basically, it's a Brian could probably describe this better, but it's it's a DSL for kinda describing your API, and then it generates the the actual implementation.
没错。
Yeah.
从我的角度来看,描述API的核心理念是,你必须花时间好好设计API,然后它会为你生成一个API,我觉得这很好。
Which from my perspective, just describing your API, the the idea behind Go was that you had to spend, you had to invest that time describing your API well, and then it it generated an API for you, which I thought was good.
我非常欣赏代码生成和单一信息源这个整体理念。
I I really like the whole idea of code generation and and single circuit source of truth.
但它生成的代码是如此优美地道的 Go 代码。
But the code that it generated was so beautifully idiomatic Go code.
我印象最深的正是这一点。
I was I was more impressed by that than anything else.
你知道,通常当你得到一个代码生成的应用时,它看起来就像一个代码生成的应用。
You know, usually when you end up with a code generated app, it looks like a code generated app.
是的。
Yeah.
这正是我想说的。
And that's that's what I was going to say.
我的意思是,当你有多年编程经验,用过那些老式的代码生成工具后,你往往会受挫,再也不愿尝试了。
I mean, when you come from, when you've been programming for a while and you use those old code generation tools, you kinda get burned and never try them again.
我很难信任它们。
I have a hard time trusting.
我信任你。
I'll trust you.
但就像你之前提到的其他事情一样,我必须亲眼看到才能相信。
So but I just like you said about something else earlier, I have to see it to believe it.
但这个网站太棒了。
But the website is amazing.
我想问一下,它也会生成文档吗?
And I wanted to ask, does it also generate, documentation?
它会生成,顺便说一声,谢谢。
It generates so thank you, by the way.
我做了这个网站。
I did the website.
代码生成会为你创建一个 Swagger JSON 文件,这样你就可以使用任何 Swagger 工具来生成 API 文档,我觉得这非常棒。
And the code generation will create a Swagger JSON file for you so that you can use the any of the Swagger tools to to provide API docs, which I think is really awesome.
所以你既能得到 Swagger 模式,也能得到可用于 API 文档的 JSON 模式。
So you you get both the the Swagger schema and a JSON schema that you can use as the documentation for your API.
它还会为你的 API 生成一个 JavaScript 客户端和一个命令行工具。
It also generates a JavaScript client for your API and a CLI command line app for your API.
所以你也可以通过命令行调用你的API。
So you can call your API from a command line too.
很多
Lots
那里有很多代码生成。
lots of code generation there.
我的2016年座右铭就是:生成一切。
Just my my motto for 2016 is generate all the things.
哇。
Wow.
好吧。
Alright.
我想这个周末得亲自试试。
I think I'm gonna have to to play with that this weekend.
嗯。
Yeah.
所以你实际上是用 Go 代码来定义 API 的,对吧?
So you you actually define the it looks like you define the API in Go code?
这是 Go 代码,但如果你熟悉那个测试框架,叫什么来着,Ginkgo。
It is it it's Go code, but if you're familiar with, what's that testing framework that is Ginkgo.
Ginkgo?
Ginkgo?
是 Ginkgo 吗?
Is it Ginkgo?
对。
Yeah.
所以有一个测试框架,我想这正是 Go DSL 的灵感来源。
So there's a testing framework, and I think that was the inspiration for the Go DSL.
所以这是一个 DSL。
So it's it's a DSL.
它看起来就像一个 DSL。
It looks like a DSL.
这确实是Go代码,但大量使用了匿名函数来让它看起来像一个DSL。
It really truly is Go code, but it uses a lot of anonymous functions to make it look like a DSL.
所以这就是你所写的。
And so that's what you write.
你编写这个描述API的DSL。
You write this this DSL that describes your API.
你描述你的端点。
You describe your endpoints.
你描述来回传输的消息。
You describe the messages that are that are going back and forth.
一旦完成,你就运行代码生成器,它会为你生成一个庞大的应用程序。
And once you've done that, you you run your code generator, and it it whips out a giant application for you.
这真的很棒。
It's really nice.
那关于
How about
那测试呢?
how about tests?
它也会生成测试吗?
Does it generate tests as well?
我想,我还没见过,但我觉得就在昨天或前天,合并了一个也能生成测试的功能。
I think, I haven't seen it yet, but I think just yesterday or the day before, merged in something that that generates tests as well.
是的。
Yeah.
这很有趣,因为你提到了它使用了大量的匿名函数来实现这个DSL。
So it's interesting because you kind of pointed out the number of anonymous functions that it uses to do this DSL.
但如果你看看其他任何语言的DSL,它们不也是这么做的吗?
But if you look at any other language that's a DSL, that's basically what they do too, right?
所以人们通常在Ruby中做DSL,但他们用的是什么?
So people commonly do DSLs in Ruby, but what do they use for that?
他们用的是代码块,对吧?
They use blocks, Right?
是的。
Yep.
都是一样的。
It's it's all the same.
而且人们会纠结,尤其是第一次看到Goa时。
And and people get hung up, especially when they see Goa for the first time.
当他们看到这个DSL时,我们会使用点导入让DSL看起来更美观。
When they look at that DSL, there's you know, we use dot imports to make the DSL look prettier.
你知道,在Go中点导入简直是灾难,但这是DSL。
You know, dot imports are are the end of the world in Go, but it's the DSL.
你知道,生成的代码并不使用点导入。
You know, the code that's generated doesn't use dot imports.
它是非常地道且美观的Go代码。
It's very idiomatic and and good looking Go.
所以别让这个DSL的外观让你太纠结。
So don't let that that DSL look hang you up too much.
这只是一个DSL。
It's just a DSL.
是的。
Yeah.
我的意思是,这只是为了生成你的代码。
And I mean and that's just to generate your code.
对吧?
Right?
比如生成的代码是地道的Go代码,所以。
Like the code that gets generated is idiomatic go, so.
没错。
Correct.
你现在正在为生成ORM通信开发一个扩展。
And now you've been working on, an extension to this for generating, ORM communication.
那是
That's
对。
right.
我看到Goa之后做的第一件事就是想,既然我们能构建API,为什么不能构建数据库层呢?
The the one of the first things I did after I saw Goa was say, well, if we can if we can build an API, why can't we build the the database layer too?
所以我试了几个不同的Go数据库访问层,最后选中了GORM,因为它是所有ORM中相对最不糟糕的。
So I played around with a couple different Go database access layers and finally settled on Gorm for being the one that's that's the least evil in terms of ORMs.
于是我做了一个
And so I made a
这又是怎么衡量的呢?
How's that measured anyway?
衡量标准是它在后台做了多少你意想不到的疯狂事情。
It's measured in how much crazy stuff it does behind the scenes that you don't expect.
至于GORM,它几乎没什么疯狂的操作。
And as far as GORM goes, it's it's almost no crazy stuff.
我的意思是,我们这个节目里的每个人,至少都用过Active Record,都曾惊讶于一条select语句竟会触发38次查询。
I mean, we I think we've all on this show at least have have all done active record in the past and been shocked by the 38 queries that happen when you make one select statement.
GORM 不会做这些。
GORM doesn't do any of that.
所以它没那么糟糕。
So it's it's not not too evil.
这很好。
That's good.
所以我为 Goa 创建了一个名为 GORMA 的插件,它允许你使用相同的声明式 API DSL 来声明你的模型,并使用类似 Active Record 的方式定义模型之间的关系,比如‘一对多’、‘属于’之类的,然后声明 API 端点与模型之间的关系。
So, I created this plugin for Goa called GORMA, which, allows you to use that same sort of declarative API DSL to, declare your models too, and then define the relationships between the models using active record style, you know, has many belongs to sort of things, And then declare the relationships between the API endpoints and your models.
因此,你只需要花几个小时思考一下它应该是什么样子,就能生成整个 API 和数据层。
So it will generate your entire API and the data layer, with just a couple hours of thought into what it should look like.
太棒了。
That's awesome.
我 definitely 要去试试看。
I'm I'm definitely gonna have to play with it.
我的 YouTube 频道上有一个视频。
There's there's a YouTube video, my YouTube channel.
要么是 B. Kettleson,要么是 Brian Kettleson。
It's either b Kettleson or Brian Kettleson.
我记不清是哪一个了。
I can't remember which.
但网上有一段我在坦帕 Go 社区活动中讲话的视频。
But there's a YouTube video of me talking at the Tampa Go meetup.
时长大约一个半小时。
It's about an hour and a half long.
我做了一个 Goa 和 Gorma 的端到端演示。
And I do a end to end demo of Goa and Gorma.
最后我还做了压力测试,以证明它有多强大。
And then I load test it at the end just to prove how awesome it is.
所以它非常酷。
So it's pretty slick.
如果我看了那个视频,算不算玩过它了?
If I watch that video, does it count as playing with it?
是的。
Yes.
好吧。
Alright.
好吧。
Alright.
这一点我承认。
I'll give you that much.
这个周末我至少会看这个视频。
I'll at least watch the video this weekend.
这就对了。
There you go.
好吧。
Alright.
在我们节目时间结束之前,我们来和特拉维斯聊一聊吧。
So before we run out of showtime here, let's let's chat with Travis here a bit.
所以,Travis,你们至少是我记得的最早公开宣布使用Go语言的团队之一。
So Travis, I mean, so you guys were one of the first, at least that I remember, to publicly state that you were using Go.
我的意思是,远在许多大公司开始大肆宣扬‘我们也用’之前,你们就已经这么做了。
I mean, definitely long before many of the big guys started waving their hands with the you know, we are too.
而且我觉得那是在Go 1.0之前。
And I think it was pre one.
我的意思是,甚至可能是在Go工具出现之前。
I mean, it might have even been before the Go tool.
你们当时可能还在用Makefile来发布产品。
You guys might have been launching with Makefiles.
所以我非常想聊聊你们的‘战斗伤痕’,以及是什么让你们如此喜爱这门语言,以至于这么早就采用了它。
So I'd really love to to to kind of talk battle scars and kind of what what made you love the language so much to adopt it that early on.
当然。
Sure.
所以当我们上线时,Go工具已经存在了,我相信是这样的。
So our decision process the Go tool did exist, I believe, when we launched.
但那是在1.0之前。
But it was pre one point o.
我们的决策过程是,基本上,我们在Ruby上遇到了瓶颈,必须做出改变。
But our decision process was, well, basically, we're hitting the wall on Ruby, and and we needed to change.
我是一名长期的Java程序员。
And I I was a longtime Java programmer.
所以我在想,我真得再回到Java来获得更好的性能吗?还是使用一些新的语言,比如当时挺流行的Java衍生语言Scala?
So it was kind of did I really wanna go back to Java to get more performance and stuff or use something new or or one of these Java derivatives like Scala was
挺流行的。
kinda popular.
调整JVM。
Tweaking the JVM.
那是什么?
What's that?
我说,因为你真的很喜欢调整JVM,你还想再搞一次。
I said because you really like tweaking the JVM and you wanna do it again.
喜欢。
Love it.
是啊。
Yeah.
你知道吗?
You know?
所以我们,你知道的,看了这些东西。
And so we, you know, looked at these things.
Scala 当时也很流行,Clojure 也很时髦。
Scala was kinda popular at the time too, and Clojure was kinda hip too.
但你知道,还有这个 Go 语言,我们看到谷歌在支持它。
But, you know, and this girl thing was there, and we saw that Google was backing in.
背后有一些非常聪明的人,我们试了一下。
There's some really smart people behind it, and we tried it.
我觉得这门语言的简洁性,以及性能几乎和 Java 一样,虽然不完全一样,但很接近。
And I think the the simplicity of the language and with, you know, almost same performance as Java, not quite, but but close.
所以我们很喜欢这一点。
So we we we like that.
我们很快就做了原型,基本上是一个队列实现,想看看能通过它实现什么样的性能。
We prototyped really quickly, you know, a a queue implementation, basically, and tried to see what kind of performance we could push through it.
而且,它表现得非常好。
And, know, it worked really well.
所以我们得说服我们的团队和投资者,你知道,你从不希望选错技术。
So we had some convincing to do of, you know, our team and our investors and stuff because you never wanna pick the wrong technology.
然后,我们就继续推进了。
And, you know, we we just moved forward with it.
结果证明,这真是个很棒的决定,幸运的是。
And turns out it was a really good decision, luckily.
是的。
Yeah.
我觉得这太疯狂了。
I think it it's crazy.
我的意思是,因为我喜欢这门语言,而且我和布莱恩也很早就接受了它。
I mean, because I love the language, and Brian and I bought into it pretty early on too.
但我不确定我们在1.0之前是否做过任何重要的生产发布。
But I don't I don't know whether we made any major production releases pre one.
布莱恩,你觉得呢?
Do you think, Brian?
我将R60或R61投入了生产。
I put, R 60 or R 61 in production.
那绝对是makefile的时代。
That was definitely make file days.
但我的意思是,那并不是应用程序的核心。
But I mean, wasn't like the core of the application.
不是。
No.
不是。
No.
它只是外围星座中的一小部分。
It was a it was one of the pieces of the constellation out on the peripheral.
对。
Right.
所以,是的,我的意思是,建立一家公司并押注它会爆炸式增长,这真是难以想象。
So, yeah, I mean, building an entire company betting on that this was going to explode is really crazy to think about.
而且,我真的很高兴我们所有人都坚持了下来。
And and, I mean, I'm glad all of us, you know, stuck with it.
而且,看看今天Go语言的处境。
And, I mean, look at where Go is today.
但你根本没看它的增长趋势。
But, mean, you you don't look at the growth pattern.
现在你可以看到增长趋势,更能看出它的普及情况,然后你可以向投资者展示,说:看,就是这样。
Like, now you can kind of look at the growth pattern and more what see the adoption happening, And you can pitch that to the investor and be like, look at this.
这只会变得越来越好。
This is only gonna continue to get better.
对吧?
Right?
但那时你什么都没有。
But then you had nothing.
你觉得有一些非常聪明的人在做这件事,但也有许多项目,很多聪明人都在做,却并没有真正成功。
You're like, there's some really smart people working on it, but there's also a lot of projects a lot of smart people are working on that that don't really take off.
尤其是编程语言。
Mean, especially languages.
语言,我都不知道该怎么预测哪一个会成功。
Languages, I don't even know how you predict which one's gonna take off.
因为我也看过其他一些语言,它们在不同方面同样吸引我,但它们的增长却赶不上Go。
Because there's other languages I've looked at that are just as, you know, interesting in different ways to me, and they they don't have the growth that Go does.
这真是令人惊讶。
It's just astonishing.
你知道,我总是思考这个问题。
There's you know, I always ponder this.
我总是很好奇。
I I always wonder.
你知道,像我们和你们这样的早期采用者。
You know, there was these early adopters like us and you guys.
我不是说我们做到了这一点,但我觉得我们这样做了,还说了它在生产环境中表现得多好,以及它如何完全超越了我们之前用Ruby写的版本。
And I you know, I'm not saying we did this, but I think us doing that and kind of saying how well it worked in production and how, you know, it totally dominated our previous version that was written in Ruby.
我觉得这类事情反而更能引起人们的兴趣。
You know, I think those kind of things probably pique people's interest even more.
对吧?
Right?
所以你们有一支优秀的团队在开发这门语言,同时还有一些公司正在生产环境中实际使用它。
So you have this great team building the language, and then you have some companies that are actually using it in production.
你知道的?
You know?
所以这有点像一种自我实现的循环。
So it's kind of a, you know, a self fulfilling thing.
我不知道。
I don't know.
我几乎不同意,因为在早期,每一篇关于你们如何从大量服务器上的慢速系统迁移到少数服务器上的高速系统的 Iron.io 博客文章,都伴随着同样多的‘我们试了 Go,它把我们吃掉了’和‘毁了我们整个公司’之类的博客文章。
I'd I almost disagree just because in the early days for every iron.io blog post about how we you guys moved from, you know, slow things on lots of servers to really fast things on fewer servers, there were just as many, we tried Go, it ate our lunch, and destroyed the entire company blog posts.
你知道,尤其是在前几年,似乎关于人们尝试 Go 的负面报道远多于正面报道。
You know, it seemed, especially in the first couple years ago, that there was far more negative press about people trying Go than there was positive press.
也许这只是我对事情的个人看法。
Maybe that was just, you know, my my perception of things.
我认为,总的来说,当时社区中所存在的热情是如此强烈,只要你稍微接触一下,就会被完全吞没。
I think collectively, I mean, the the passion that existed in the community as it stood was so great, though, that if you dipped your toes in, you kind of got swallowed.
对吧?
Right?
你就是被拉进去了。
Like, you just got pulled into it.
我觉得这也是我们之前讨论过的一些内容,我认为我们如此喜欢它的原因,是因为这门语言本身非常简单。
And I think that was some of the stuff that you know, we've talked about this before too, that I think the reason that we loved it so much is the language itself was so simple.
你知道,你可以理解代码,然后当然还有并发性和性能之类的东西。
You know, you could reason about the code, and then, of course, concurrency and performance and things like that.
所以这足以引起你的兴趣。
So that was enough to pique your interest.
然后你就成了Golang迷,开始与那些极其热情、乐于帮助任何对这门语言感兴趣的人互动。
And then you kind of got into the, Golang nuts, and you started interacting with all these people who just were were so passionate and just so eager to help anybody who also shared this interest in the language they loved.
我觉得这把我们所有人都吸引进来了。
And I think it kind of pulled all of us in.
我觉得这就是为什么我们所有人现在都试图为支持我们的社区回馈一些东西。
And I think that's why all of us all of us here are kind of trying to do things back to for the communities that hold us in.
对吧?
Right?
你们运营着规模最大的Go线下聚会之一。
Like, you guys run on one of the largest Go meetups.
是的。
Yeah.
罗布·派克曾在我们早期于Heroku举办的一次活动中发言。
Rob Pikes, spoke at one of our early meetups at Heroku.
那大概是三四年前的事了。
It was probably, like, three or four years ago.
他出人意料地表示,大多数使用Go的人来自Ruby、Python和JavaScript,而不是像他们预期的那样从C和C++转过来以简化生活。
And he said, surprisingly, that most of the people that were using Go were from Ruby and Python and JavaScript, not they they were expecting people to kinda switch from c and c plus plus to make their lives easier.
但事实证明,很多使用者来自这些脚本语言,他们希望获得更好的性能。
But it turns out it was a lot of, you know, these scripting languages where people wanted more performance.
但他们拥有一种类似脚本语言的、可编译的系统级语言。
But they had this, you know, compiled systems language that wrote sort of like the scripting languages.
是的。
Yeah.
我根本没想到会是这样。
I don't think they predicted that at all.
而且,确实吸引了很多原本觉得系统编程遥不可及的人,因为他们见过C、C++,也许还接触过一些汇编语言,觉得那远远超出了他们的能力范围。
And, I mean, it it definitely pulled a lot of people in, people who wanted to do systems programming that felt like maybe it was unapproachable because, you know, they've seen c, they've seen c plus plus they've seen maybe some assembly, and it just seemed, you know, beyond their reach.
还有些人使用脚本语言,因为觉得那样更高效,他们不想再用 C 和 C++ 做事情,而现在他们有了一个既能获得性能、又不会像用 C 和 C++ 那样牺牲生产力的工具。这么说可能不公平,毕竟肯定有很多人用这些语言同样高效。
And then there were people who, you know, used descripting languages because it just it was felt more productive, and they didn't wanna do things in C and C plus plus and now they had something that they could get the performance without the kind of the productivity losses of doing things in C and C plus plus That may be unfair to say, but for the productivity losses, I'm sure there's people who are plenty productive with those languages.
我认为,在使用像 C++ 这样复杂的语言时,会有很高的认知负担和认知开销。当你面对模板和大量代码时,要真正高效地工作是很困难的。
Well, there's I think there's a cognitive load, a cognitive overhead when you're working in something as deep as C plus plus You know, when you've got templates and all of that code, it's, it's difficult to be really productive.
但另一方面,如果你反复做同样的事情,就能大量复用代码。
On the other hand, if you're doing the same thing over and over, you reuse a lot of your code.
所以,当然,用这种方式你也可以非常高效。
So sure, you can be very productive that way.
我觉得 Go 也是这样,它的语法非常简洁精炼。
I feel like that with Go as well, just the syntax is so concise and small.
我感觉自己一直在重复使用同样的东西,久而久之,我思考的不再是‘我该怎么实现这个?’,而是直接聚焦于眼前的问题。
I feel like I'm using the same thing over and over again, which at some point I'm just thinking about the problem ahead of me as opposed to, Oh, how do I do this?
或者‘我该怎么实现那个?’
Or how do I do that?
这完全是两回事。
It's completely different.
嗯,是的,这属于小型语言。
Well, yeah, goes to small language.
有多少个关键字?
How many keywords?
67个关键字?
67 keywords?
大概是这个数量。
Something like that.
而且其中有两个非常奇怪的关键字,比如'whereas',我们只是加进去图个好玩。
And and two two of them are crazy keywords like whereas that we put in just for fun.
就为了好玩。
Just for fun.
我真的很喜欢你不需要代码生成。
I really like that you don't need, code generation.
从Java过来,你知道,你得用一个大型IDE,它能做很多重构,自动生成所有的getter和setter以及这些代码。
Coming from Java, you know, you you had to use a big IDE that could do a bunch of refactoring and generate all your getters and setters and all this code for you.
而Go语言,你真的不需要这些东西。
Whereas Go, you don't really need any of that stuff.
是的。
Yeah.
简单的文本编辑器就能让你在Go中生活轻松。
Simple text editor makes makes your life easy in Go.
我同意。
I agree.
你可以把整个代码模型记在脑子里。
You can keep that whole code model in your head.
嗯。
Mhmm.
这很疯狂,因为我一直用Vim,但Java是我唯一不会尝试用Vim写的语言。
It's crazy because Vim I I live by Vim, and Java is the only language I will not try to do in Vim.
是的。
Yeah.
这是唯一的一个。
That's the only one.
我想,好吧。
I'm like, alright.
好吧。
Alright.
我还是直接装个IDE吧。
I'll just install the IDE.
没错。
Yep.
感觉真的太痛苦了。
It just feels that painful.
所以,特拉维斯,你刚开始用Go时遇到了哪些痛点?
So, Travis, what kind of what kind of pain points did you hit, early on with Go?
你遇到过长时间的垃圾回收暂停吗?
Did you run into, big garbage collection pauses?
你有没有遇到过什么特别疯狂的情况,比如早期不得不去诊断的问题?还是说对你来说相对顺利?
Did you did you see anything crazy like that that that you ended up, you know, having to diagnose early, or or was it relatively painless for you?
你知道,这已经是很久以前的事了,但我认为我们获得的好处如此显著,以至于我们可能忽略了大部分缺点。
You know, this was a while back, but I think the benefits we gained were so significant that we probably overlooked a lot of the drawbacks.
但没错,我想主要是当时可用的库并不多,其他类似的东西也很少。
But, yeah, I mean, I think probably it was mostly the amount of libraries and whatnot that were available at that time, which there weren't that many.
而且其中很多库都没有经过充分测试,诸如此类的问题。
And there weren't that many that were well tested and things like that.
比如数据库驱动程序之类的东西。
You know, like database drivers and stuff like that.
它是什么?
It was it was what?
也许一周前,布莱恩和我也在回忆这件事。
Maybe a week or so ago, Brian and I were reminiscing on that too.
我不是说,呃,不是在好的意义上说的。
I don't I don't I mean, not in a good way.
但回想起过去,与今天相比,现在的人们要轻松多了,因为那时候你得自己编写所有库。
But thinking back on and look comparing to today, how much easier people have it because you had to write libraries for everything back then.
我小时候,连数据库和SQL都没有。
When I was a kid, we didn't have DB SQL.
那时候,我们第一个上线的Go应用,数据库和SQL都还不存在。
Just just for way that but the first Go app we put into production, DB SQL didn't exist.
是啊。
Yeah.
是啊。
Yeah.
太疯狂了。
Crazy.
是啊。
Yeah.
而且,有些东西现在我们经常能看到。
And I mean, some of the stuff too, I mean, like, we constantly see stuff now.
今天早些时候我看到的一个是用 Go 编写的 OCR。
One of the ones I saw earlier today was OCR written in Go.
现在你几乎能找到任何东西的项目。
Just I can find you can find projects for everything now.
嗯。
Mhmm.
是的。
Yeah.
这要求很高。
That's high.
Go 社区推出的库质量真的非常高,很多都特别出色。
It's really high quality that the libraries that come out of the Go community seem they're just a lot of them are really exceptional.
你知道的?
You know?
是的。
Yeah.
它们很强大。
They're strong.
我同意。
I agree.
Go 语言似乎吸引了许多聪明且具备扎实工程思维的人。
Go seems to attract really bright people that have, solid engineering minds.
还有我。
And then me.
我认为 Go 还受益于 Ruby 开发者群体经历过的测试驱动开发浪潮。
I think Go also benefits from the wave of test driven development, all the Ruby developers went through.
这是我所熟悉的。
That's what I'm familiar with.
但在发现 Ruby 之前,我并没有这样做。
But before I found Ruby, I wasn't doing that.
我甚至根本不了解该如何做。
I didn't even really understand how to do it.
现在这些开发者在使用Go,他们将这些良好的实践带入了社区和他们的开发中。
And now these developers are working with Go, and they bring all of those good practices into the community and into their development.
所以这非常好。
So it's very nice.
正如他们所说,Go是一种现代语言,并且在很大程度上受益于以往的经验。
Just as they say, Go is a modern language and it's benefiting from past experiences in a big way.
是的。
Yeah.
这是个很好的观点。
That's a good point.
我还想补充一点,看起来大多数Go库的开发者也在测试性能。
I'd like I'd add to that too, that it seems like most Go libraries, people are testing for performance too.
是的。
Yeah.
如果他们没有,其他人也会做。
And if they aren't, somebody else is.
有个人只是在默默爬取。
There's there's somebody who just crawls.
布赖恩下载那些优秀的项目。
Brian downloads the cool projects.
还有人去发现优秀的项目,并提交PR来减少内存分配。
Somebody else goes and finds the cool projects and submits, PRs to reduce allocations.
是的。
Yeah.
太棒了。
It's amazing.
在Ruby里,你从来没见过这样的情况。
Which which in Ruby, you never saw.
比如,它们虽然测试得很充分,但性能根本没人关注。
Like, per they they'd be well tested, but the performance, I don't think it was even looked at.
根本没人关心。
Nobody cared.
是的。
Yeah.
是的。
Yeah.
也许是因为那种‘何必费劲’的心态,或者我也说不准。
Maybe it was just like the why bother mentality or I I don't know.
我的意思是,虽然我现在对那个世界有点脱节了,但看起来在Rails的很多库中,人们也在进行各种疯狂的尝试,比如减少内存分配之类的。
I mean, there's some I've I've I'm a little disconnected from that world now, but it seems itself and a lot of the Rails libraries people have been going on these these crazy endeavors to reduce allocations and things like that there too.
所以,也许这是一种到处都在发生的趋势。
So may maybe it's a trend that's happening everywhere.
我不知道。
I don't know.
这在Go语言中显然更普遍。
It's it's definitely seems more prevalent in Go.
是的。
Yeah.
我认为这是Go语言思维的一部分。
It's I think it's it's part of the Go mindset.
是的。
Yeah.
是的。
Yeah.
我正想说,人们选择Go是因为很多原因都是出于性能考虑,所以我觉得库也得跟上这一点。
I was just gonna say that I think people choose Go because well, a lot of it's because of performance, so I think the libraries have to kinda follow suit.
是的。
Yeah.
这也对。
That's true too.
如果你选择Go是为了性能,那你确实应该关注自己是否以高效的方式使用它。
If if you're going to choose it for performance, you might wanna actually pay attention to the fact of whether or not you're you're doing it in a performant manner.
是的。
Yeah.
这让我想起了我第一次尝试为Go语言本身修复一个bug而添加功能。
That that reminds me of my my first attempt to to make an addition to the Go language to fix a bug Go proper.
我想是在encoding模块里,可能是base64编码。
I think it was in encoding somewhere, like maybe base 64 encoding.
我解决了问题,修复了bug,写了测试,全都做完了。
And I solved the problem, fixed the bug, wrote a test, all of that.
然后我提交了CL,立刻收到了一条评论。
And, I submitted the the CL and I got back a comment immediately.
这完全解决了问题。
This absolutely solves the problem.
但我需要你重构一下,去掉你新增的三个内存分配。
I need you to refactor it to reduce to to get rid of the three allocations you added.
我盯着那封邮件看了五到十分钟,想不通自己哪里增加了内存分配,更不知道该怎么去掉它们,因为我根本不知道是怎么回事。
And I stared at my email for a good five or ten minutes wondering what I did to add allocations and how in the world I was gonna get rid of them because I didn't know.
我以前是用Ruby的。
I came from Ruby.
我不关心分配。
I didn't care about allocations.
我老实说一般也不关心分配,但我当时不知道该怎么办。
I still honestly don't care about allocations generally, but I didn't know what to do.
我去找了埃里克。
I grabbed Eric.
埃里克,我该怎么办?
Eric, what do I do?
不过说来有趣,我一看代码就能发现一些明显的分配,但其他人却完全碾压我。
It's funny, though, because, like, I look at code and I'll see some of the allocations that are obvious, but other people, they just totally outshine you.
他们看一眼就能说,这里有五个分配。
They look at something really quick, and they're like, there's five allocations there.
你会说,什么?
You're like, what?
你凭什么看一眼就知道?
How how do you know that just by looking at it for a second?
我得逐个去数一遍。
I have to go through and count.
没错。
Yep.
那个会是一个分配,那个也是一个。
That would be an allocation, and that one would be one.
你懂的?
You know?
但你知道吗,我觉得在核心团队内部,这几乎像是一种游戏。
But You know, I think on the core team, it's it's almost like a game in inside the team.
我记得布莱克·米佐拉尼。
I I remember Blake Mizorani.
他可能不在核心团队里,但他和布拉德·菲茨帕特里克那些人关系非常密切。
He's I I don't think he's on the core team, but he's very close with, you know, Brad Fitzpatrick and those guys.
我觉得他们几乎在进行比赛。
I think they almost have competitions.
我想他写了一个日志解析器,用来解析日志缓冲。
I think he wrote a a log parser, like, to parse log bump.
他的目标是实现零分配,或者类似的东西。
And his whole goal is to have, like, zero allocations or something like that.
但他确实做到了,现在有了一个在解析日志时完全不分配内存的日志解析器。
But he did it, so now there's this log parser that doesn't allocate anything while it's parsing logs.
太棒了。
Awesome.
我得结束这个通话,去查一下 Go 语言中分配是如何进行的,如何识别它们,以及如何解决它们。
I'm gonna have to end this call and go look up how allocations are done in Go, how to recognize them, and how to solve them.
我不懂你们在说什么。
I don't know what you guys talking about.
实际上,最近 Prometheus 团队的 Bjorn Ravenstein 做了一场演讲,我念他的名字应该没错。
So actually, there was a talk by, I'm pronouncing his name right, Bjorn Ravenstein recently from the Prometheus team.
他做了一个演讲。
He did a talk.
我们会在节目笔记中提供链接。
We'll link in the show notes.
我认为他其中一部分内容是讲解了内存分配,你可以实际看到变化。
And I believe some of that, he walks through the allocations, and, you know, you can actually see the change.
所以这可能是一个很好的参考。
So that might be a good look at it.
我觉得还有另一个,我会帮你找一下,等我找到后就放到节目笔记里。
And I think there's another one too, and I'll look it up for you, and we'll put it in the show notes when I find it.
我觉得我之前也看过另一个,有人在分析代码,判断某个东西是栈分配还是堆分配,类似这样的内容。
I think there was another one that I'd seen a while back too, where somebody was walking through, looking at code and determining whether something was gonna be, stack allocated or heap allocated and things like that.
所以,是的,我们会找到那个链接。
So, yeah, we'll We find that link to
之前我们稍微谈到了静态分析工具。
talked a little bit earlier about the static analysis tools.
也许可以开发一个非常简单的静态分析工具,帮助你理解正在发生的内存分配。
Maybe there's an opportunity for a really simple static analysis tool that helps you understand the allocations that are being made.
我的意思是,我知道你可以使用内置的基准工具来显示内存分配情况。
I mean I know you can use, the benchmark tools that are built in to show you allocations.
但一个友好且易于使用的静态分析工具,能清楚地展示哪些地方发生了内存分配,并建议如何减少这些分配,那就太棒了。
But, a nice SSA tool that's you know Brian friendly would be pretty awesome to show you know, what allocations are being made and maybe suggest changes to reduce those.
不过,有些情况也会变得复杂,因为如果工具能建议修改,那你就可以直接改了。
Well, some of them get hard too because, you know, if they could suggest the change, you could make the change.
所以,有两个工具在这方面特别好用。
So there's there's two tools that are really good for it.
一个是使用标准的基准测试和测试功能,你可以用 pprof,然后在 pprof 工具中查看,或者进行可视化。
One is just using the standard benchmark and test stuff where you can do the pprof, and you can you can look at it in the pprof tool, or you can visualize it.
这些工具对于查找内存分配非常出色。
And those are great tools for looking for allocations.
但另一点是,Go 编译器本身提供了命令行标志,你可以传入参数,它会告诉你每次指针逃逸并需要在堆上分配的情况。
But the other thing is is there's Go command line flags for the Go compiler itself, where you can pass it in, and it will tell you every time that a pointer escapes, and it needs to be allocated on the heap too.
因此,在编译时运行这个功能也很有意思,这样你就能看到你原本以为不会发生的情况是否真的发生了。
So that's also an interesting thing to run on your code during the compile the compilation so that you can see whether or not maybe something that you thought didn't.
而且这很有趣,因为在通话中很难解释,因为我不可能直接给你看代码示例。
And and it's interesting just because of the way it's hard to talk about over, you know, a call because you can't I can't, like, give you code examples.
但我可以找一些视频资料,然后把链接放在节目笔记里,我可以发给你。
But, I'll find, some videos and stuff, and we can link them in the show notes, I can send them out.
但其实并没有你想象的那么复杂。
But it's not as as complex as you'd you'd think.
有那么几个地方,你知道的,它们会分配内存,而更难的是确定你调用的那些库最终会为你分配内存。
There's a a couple of areas where, you know, they're And then the harder part is determining libraries that you call that end up allocating for you.
然后不小心传入一个指针,导致它逃逸到堆上,从而必须在堆上分配,而你可能根本没注意到这一点。
And then accidentally, you know, passing a pointer that ends up escaping the heap or escaping and then having to be allocated on the heap, and you may not have noticed it.
但没错。
But yeah.
是的。
Yep.
我能理解。
I can see that.
正如你所说,对大多数人来说,大多数时候这并不重要。
Like you said, I mean, most of the time, it it for most people, it doesn't matter.
当你试图达到规模时,你们之前说每秒要处理多少请求来着,特拉维斯?
When you're trying to hit the scale how many requests a second did you say you were you guys were shooting for, Travis?
一百万。
A million.
是的。
Yeah.
你看,当你想达到这种规模时,内存分配就变得重要了。
See, when you wanna hit like that, then allocations matter.
对吧?
Right?
因为垃圾回收器会占用时间,内存分配也会耗费时间。
Because a garbage collector comes into play taking up time, allocations take up time.
所以当你想达到这种规模,或者像Prometheus那样,我听说他们正在讨论每秒五十万次请求。
So when you wanna hit scale like that or Prometheus, I think they were just talking about half a million requests a second.
关于 Bayt 播客
Bayt 提供中文+原文双语音频和字幕,帮助你打破语言障碍,轻松听懂全球优质播客。