 Okay, I'm one of the network guys as you can guess by the t-shirt so hopefully the network was working, okay, and How a networking guy can talk about the networking protocol at an application developers conference Well add this protocol into a cool application and then talk about it and talk about both So we will start talking about the mongrel 2 If the slides go and change, okay So mongrel 2 first of all is a really a Lego building block for building your web applications So you have clients coming in on the front end connecting by normal HTTP requests or if you do the things like web chat you can do long polling or You can have the flash Applications on the client side connecting to the mongrel 2 using the flash sockets and what mongrel 2 does is that it Converts those requests on the back end into the zero MQ Messages and you connect your back-end handlers via zero MQ to the mongrel front end So what this gives you is very much flexibility and language agnosticism. So you don't care which Language your back-end is written in so the mongrel is very much language agnostic in this case Now it obviously also handles the static files and the reverse proxy Manageability of mongrel 2 is also a very interesting thing. It has its configuration Embedded into the sqli 3 database So why that that means that you can not only use the built-in m2sh So mongrel shell that is used to control the operation of mongrel 2 to convert the standard text configs into sqli 3 but you can also Use your own configuration database and then you can integrate sqli 3 That mongrel 2 uses together with your configuration back-end another interesting thing is that you can use the rails like Routing so you specify which handle attaches to which URL subtree. So think of it like mounting of the volumes under any of the Unix operating systems Efficiency so how many people in the room worked with the mongrel with the previous Generation thing Okay a few What's mongrel and mongrel 2 have in common is the skeleton So the skeleton is the ragel made parser for the HTTP protocol and it's formally Generated code from the description of the HTTP protocol taken from the RFC. So as a result The performance of this parser is quite good And also the number of bugs that you create when you make the code manually is also much lower So you have automatically generated parser And this gives both the performance and the strictness of the parsing On the back-end at the same time we have 0mq. So 0mq is very lightweight messaging library and Using this library again allows to abstract from any language any kind of Protocol that is used to signal with the back-end Because with 0mq if you were I think there is Another lightning talk on 0mq Library itself and you can see there that the number of languages that the library supports is astounding. So there is probably 15 to 20 languages that it supports. So that's a really good thing Now the For me I wanted to have a great web server to use that would support IPv6. So mongrel 2 was perfect candidate with one Detail that they didn't support IPv6 So I started digging into the code and looking how the networking part is implemented and the networking part is implemented as part of leap task which is really a task library by Rose Cox and The abstractions that are in that library are really pleasant to work with so effectively You don't need to work with this one-time use structures Where you take the name then you convert it into the structure and then you just use that structure once So all of that is obstructed inside the library So effectively there are three primitives that are there that you need to work with it's announce the socket then start connecting to a client server and Accept the incoming connections. So this provides an abstraction layer from the rest of the code and How to add IPv6 there's plenty of documentation on the web So I just picked one of them which shows the example of code before porting to IPv6 and after porting IPv6 support. So I basically just went through the same logic as was there Obviously What I showed in the previous slide this very nice level of abstraction also gave Very few changes in other places in the system So there was only one one place to change in the remaining part of the code of mongrel 2 which is kind of giving an impression of the niceness of the quality of the code base Another assumption that I made was that bindv6 only variable is set to 0 So we'll talk a little bit about that variable later on now after I made this code then we Shaped the mongrel 2 with the support and there came some interesting problems So first of all Get address in 4 is not cached So when we use it in a reverse proxy and the configuration specifies the target by name then per Connection attempt to the backend server. We have at least one DNS request Well, in reality, it's two packets the IPv4 and IPv6 resolution attempt So that's not very performative. You have DNS server a couple of hopes away. So you Would either put the DNS server closer or maybe in the future We will change the logic a little bit by adding the local cache Now another interesting point that I heard is that some people at this day Don't have the kernels with IPv6 enabled at all So my optimistic assumption that hey, well if I net I need six socket will be just created it failed and finally Which is not specific to IPv6 Was the increased latency in serving the request because there is no non-blocking name resolution interface in the socket library So for the users who don't have IPv6 in the kernel Basically that came up with an interesting hack where you explicitly specify the bind address So if you specify the v4 wildcard bind address Then you bind only to v4 address family and then you work around this fact that some people don't have the v6 Support in their kernel or if you if you're ready when you're ready to deploy v6 Then you can just change that variable to colon colon, which is the wildcard for IPv6 address and then you can bind your server to IPv6 socket now a little bit of France about having to deal with two address families is that I know tend to pee is not really suited for printing out the socket addresses because It deals with the address as itself Whereas in the code you mainly deal with the socket structure where you have the address and the port So then you need to have a little bit of this Kind of slightly spaghetti code that has if families for then do this or if families six Then do that which is a bit of inconvenience because I would expect every program would need to have this kind of operation now Remember I mentioned the single socket so the bind v6 only it's a very interesting feature where you are able to port Your v4 applications in my opinion Much easier because you had one socket before and you still have only one socket afterwards It's just that this socket can handle both v4 and v6 addresses kind of magically So your previous v4 space gets mapped into v4 mapped addresses on this socket. So On the other hand, there are different opinions. So this was my opinion from the implementation point of view there are other implementers who may have other opinions and This setting had an interesting history It was first on then off and finally now it's again on in the Linux by default, but in BSD it's off by default Another interesting problem is address family selection. So it was not really a Big problem, I think for the mongrel 2 code per se because normally the scenario that Where we use the name resolution as a client Implied that we have both the backend server and mongrel 2 as a client So in this case both hosts are in the same administrative domain So you can fix if something is broken, but if you are developing applications that Our only client side and if you have the applications that require the real-time user response Then you probably would need to deal with it somehow less Relaxed manner, I would say that RFC 3484 specified because 3484 just says okay, you first select the six and then you start going by the addresses you get from get addressing for So for that me and one of my colleagues, we had a small internet draft on with the idea of how to do the address selection And also very recently Mark Andrews from ISE he published a blog post where he Specifies a different algorithm, but probably more efficient than ours where he bounced the connection time by fixed interval Now obviously all of these cool things for user experience are not to replace fixing the brokenness Finally a few conclusions that I've taken for myself from this mongrel 2 IPv6 exercise is that Well first mongrel 2 is really awesome application. So if you don't hack on anything open source I would really invite you to start playing with it and use it in your project By the way, the stats for the network So if you looked at the stats for the network at Fosdm.istdio.b, so that's my domain They were sort from mongrel 2 so I'm not going to demo it because we were demoing it for the past one and a half days and Really adding v6 in itself is not that much of a big deal But tuning it and making sure that it works correctly for all the users That's something that needs Sometime so really if you have your application it doesn't support v6 Then you would really want to start now and start to exchange opinions on how things work better So with this I would like to thank you and open for questions if any Yes, there are thoughts to add the non-blocking DNS But looking so the question was are there thoughts to add the non-blocking DNS There are thoughts and we've been trying very hard to find the asynchronous DNS resolver library that Well to state it politically correct that that would work Because the existing ones are interfering very heavily with the green threads that are used in the mongrel 2 because they They basically either start threads or they fork a process or they do some other weird things from from just underneath your back So I have some very very initial code, but it's not yet the async resolver as such So performance benchmarks The get other info is something that is really hurting quite a lot so in terms of Pure static files. I think that I don't have the exact data But I think they should be pretty much the same So protocol wise there is not a whole lot of overhead and code wise the paths as I said, they are very very similar So basically we use the exact same Socket code for v4 and v6 with the only difference that the well this this part is one of the few places Where it's different. So otherwise, it's exactly the same code