text
stringlengths
0
1.82k
**Scott Mansfield:** So the purpose of Rend, actually... So for us, Netflix as a whole has changed into a N+1 architecture globally. What that means is any member can be served from any region that we have. We operate in three AWS regions, and as the caching layer for the company, we actually do global data replication...
It's really expensive though, when you have all of this data that's stored multiple times in RAM when it's really only read in one region. So the purpose of this overall project that we called Moneta was to store some of that cold data on disk, and allow the hot data to still be served from RAM as fast as it could be, ...
As a part of that now, Rend is the on-box memcached proxy that does... It's a wire-compatible memcached proxy; our client didn't change at all, it still uses the same Java memcached client that we were using before. That's actually sort of the secret sauce of the EVCache product, and it speaks to Rend.
**Erik St. Martin:** That's one of the things I found most interesting, that you kind of got this layer 1, layer 2 built-in, except it was wire-compatible, so you didn't really have to rewrite anything to use a new caching layer, you just talked to it as if it was a memcached.
**Scott Mansfield:** Yeah, so our upgrades are pretty much just doing another deployment, and we get instantly more efficient storage.
**Erik St. Martin:** Do you have anything special between the two layers? Did you implement Bloom filters or anything like that to save seeking the data off-disk if it doesn't exist there, the cold data? Or is it almost guaranteed to exist when you're looking for it in memcached, in your particular use case?
**Scott Mansfield:** Not necessarily true. When you do things like [Chaos Kong](https://netflixtechblog.com/chaos-engineering-upgraded-878d341f15fa) where we evacuate a single region and split it between the other regions, you might have a huge number of misses in L1 very quickly. I didn't actually work on the RocksDB ...
**Erik St. Martin:** \[11:43\] Yeah, RocksDB has been a favorite of mine for a long time. I'm kind of jealous you guys got to build something really cool with it. So walk us through the performance of that. You spoke to having to kind of go against the idioms to get the type of performance that you are, the one-millise...
**Scott Mansfield:** Part of it was the design itself is less... I'm trying to think of the proper words here. Most people might immediately think like, "Okay, send messages back and forth so that you could do requests", but for us, we have a connection coming in as a connection going out, so we have these sort of vert...
There's not too many places where I've bucked the trend; I've just tried to avoid over-abstraction. So for the metrics library, for example, counters are AtomicIntegers, and it's a pretty straightforward thing that you would think to do.
**Erik St. Martin:** Right. And there's been a couple of instances that we were talking about the other week, Heka... He believed that they had overused channels too, and that they could have got much better performance had they just stuck to using mutexes and AtomicIntegers and things like that instead of all the chan...
**Scott Mansfield:** Yeah.
**Erik St. Martin:** So I think naturally we wanna use all this stuff because it's cool and it's new, and the languages that we came from didn't have them, and I totally abuse - I should go to jail for my abuse of channels when I first came into Go. I wanted to use them for everything.
**Scott Mansfield:** I think that's a pretty common pattern, though. Everybody comes in and, "Oh look, concurrency, parallelism. Channels everywhere", and then we calm down.
**Carlisia Thompson:** That happened to me, to use channels and ask for some advice about my code, and people were like "Just use a mutex here." So I would say for people who are starting out, learn how to use a mutex so that you can then make a choice if that's what you need, versus channels. A lot of times that's eno...
**Scott Mansfield:** I also think it's important to remember that nothing is magic, so for a channel there is a fast path - think buffered channel, not the one where you need a handshake where there's no buffer. But for a buffered channel there's no magic. You have pretty smart code at the front whenever you're trying ...
**Erik St. Martin:** Yeah, and I know some of this stuff, too. This is one of the things I was guilty of early on, I was using channels for state. When I should really be using a mutex, I would create these goroutines that select on channels, and that's where the updates took place to state, and that seemed like the pa...
**Brian Ketelsen:** I think I have a pretty good idea. If you're at Netflix scale, then all of the rules don't apply. But if you're not at Netflix scale, use whatever you want I think we've probably spent too much time focusing on tiny microperformance benchmarks, when 90% of our latency comes from the network and the ...
**Carlisia Thompson:** \[16:11\] My impression though is that mutex and channels, they are not interchangeable. I mean, you can use channels in the way that you would... If all you needed was a mutex, you could force a design with channels in your code, but they're not really the same thing. I could be wrong.
**Erik St. Martin:** No, they're not. They're not at all. The only way it ends up working that way is because you end up having one goroutine that is the thing always updating state. It's almost used that way, but I think the pattern kind of came from - I think there were some projects early on that had that pattern, a...
**Carlisia Thompson:** And while on the subject, I just wanna mention this real quick: if you do figure out that a mutex is not gonna do it for you and you do need to use channels, if you haven't, it's worthwhile to watch a Rob Pike video on Concurrency Design In Go. I think that's what the name is... I'll put the link...
**Erik St. Martin:** Yeah, yeah.
**Carlisia Thompson:** Of course.
**Erik St. Martin:** So for Rend, is that pretty much done? Are you actively maintaining it or are you adding new features?
**Scott Mansfield:** Well, at this point it's mostly done. It's got a couple new things I'm adding to it, mostly to support new memcached commands, because we're supporting each one very explicitly; sometimes I have to go in and edit code to add support for things like append() or prepend(), or things like that. It's i...
**Erik St. Martin:** Now, are you gonna continue to support changes so that it stays wire compatible with memcached, or you're just kind of staying at the current version? Does it support all the commands that memcached offers?
**Scott Mansfield:** It doesn't really support everything that memcached offers, and there's no plan to be completely a hundred percent wire compatible, because there's some things that we just simply don't use. Our EVCache Java client that we vend to people does not expose everything, so we don't worry about supportin...
**Erik St. Martin:** Okay.
**Scott Mansfield:** It's a very pragmatic approach, because it's meant to solve Netflix problems, and it's open source in the hope that it will help somebody else solve their problems as well.
**Erik St. Martin:** I don't think that there's a need to be 100% either. There's a big project that came out of YouTube called Vitess which is wire compatible with MySQL, but kind of makes MySQL distributed, and they don't support all SQL in there as well, just kind of the core things that they use.
**Brian Ketelsen:** And that's okay, definitely if it solves their problem. I agree.
**Erik St. Martin:** And if it does not solve your problem... Pull requests accepted.
**Brian Ketelsen:** \[20:01\] Or forks.
**Erik St. Martin:** Right, or forks. Kind of on a different track here - was it yesterday, or the day before? - I came across another one of your blog posts, which I actually love, which was called How To Block Forever In Go. That was kind of like a list of all the different ways... Are these just things you came acro...
**Scott Mansfield:** Not strictly. I think it's still in the Rend code, I have been making a new wait group and then adding one and trying to wait on it so it could block forever in my main and of course, I thought that was a little bit absurd. So a while ago we were talking in the Gopher Slack about this, and I mentio...
**Erik St. Martin:** It was probably ten or more... There was quite a few, and I actually have one that's missing.
**Scott Mansfield:** Yeah, that's the great thing about it. I learned the proper way to do it, which is the runtime.go exit I think, in the main, which allows you to exit out of your main but allow every other goroutine that you've started to keep running. So that's the proper way to do it, and I didn't know that. It's...
**Erik St. Martin:** So wait, what was it? You said runtime.exit?
**Scott Mansfield:** It's called go-exit, I believe...
**Erik St. Martin:** Yeah, something along those lines, I can't remember now. It's one of those things, you have to be there ready to type it, and then it comes to your mind. Well, nowadays you don't even have to do that, because of the editor plugins...
**Brian Ketelsen:** Yeah, VimGo...
**Erik St. Martin:** The one that I remember not being on the list is a nil channel will also block forever. So if you try to send or receive on a nil channel, it will block forever.
**Scott Mansfield:** I need to add that now. I feel like it's not complete.
**Erik St. Martin:** \[laughs\] I think it should just be like a never ending list that evolves.
**Brian Ketelsen:** Yeah, that's the power of the internet. You can go back and edit it, and nobody will ever know.
**Erik St. Martin:** Yeah, and for everybody who's listening who has not seen this post, we'll link to it in the show notes, but it's basically this running list of different things you can do that would end up making your program deadlock; or the goroutine or the application itself just blocks forever. It was a fun re...
**Brian Ketelsen:** I did that this week. Yep... Oops!
**Erik St. Martin:** And I feel like some of the static analysis tools that are out there could be evolved to look for some of these patterns. I mean, some of them are Runtime-specific, right? You can't know that the channel is gonna stay empty forever, but others like the double locking I feel like you should be able ...
**Brian Ketelsen:** It should be easy.
**Erik St. Martin:** Right? For anybody who writes static analysis tools... Hey, it's no different than the business delivering requirements, right? It's just a button. How hard could it be? Just add the button.