Ruby Rogues
122 RR Daemons with Kenneth Kalmer
Kenneth Kalmer comes on the show and discusses the ins and outs of long running processes and when and how to manage daemons in Ruby.
September 11, 2013
1:12:32
Episode 122
Special Guests
122 RR Daemons with Kenneth Kalmer
Ruby Rogues
1:12:32
0:00
1:12:32
Speed:
Share This Episode
Show Notes
Kenneth Kalmer comes on the show and discusses the ins and outs of long running processes and when and how to manage daemons in Ruby.
Special Guest: Kenneth Kalmer.
Transcript
KATRINA:
Can you say, āI believe I broke his jawā?
KENNETH:
Who, me?
KATRINA:
Yes, you. Of course, you.
KENNETH:
I believe I broke his jaw.
KATRINA:
Ah! Itās so brilliant.
JAMES:
Okay, now you have to explain that.
[Laughter]
KATRINA:
I think at the first Mission Impossible movie, there are some really bad guys from South Africa and one of them says, āI believe I broke his jaw,ā and itās so funny. [Laughter]
CHUCK:
Okay.
[Hosting and bandwidth provided by the Blue Box Group. Check them out at BlueBox.net.]
[This episode is sponsored by JetBrains, makers of RubyMine. If you like having an IDE that provides great inline debugging tools, built-in version control, and intelligent code insight and refactorings, check out RubyMine by going to JetBrains.com/Ruby.]
[This podcast is sponsored by New Relic. To track and optimize your application performance, go to RubyRogues.com/NewRelic.]
[This episode is sponsored by Code Climate. Code Climate automated code reviews ensure that your projects stay on track. Fix and find quality and security issues in your Ruby code sooner. Try it free at RubyRogues.com/CodeClimate.]
CHUCK:
Hey everybody and welcome to episode 122 of the Ruby Rogues podcast. This week on our panel, we have James Edward Gray.
JAMES:
Good morning everyone.
CHUCK:
Josh Susser.
JOSH:
Everything done for the first time unleashes a daemon.
CHUCK:
Katrina Owen.
KATRINA:
Hello.
CHUCK:
Avdi Grimm.
AVDI:
Hello from Pennsylvania.
CHUCK:
Iām Charles Max Wood from DevChat.TV. And this week, we have a special guest and that is Kenneth Kalmer.
KENNETH:
Hi from springy Johannesburg.
CHUCK:
Wow! I donāt think weāve had anyone from that far south before.
KENNETH:
Iām glad to be here and to represent the whole southern hemisphere.
CHUCK:
So, youāre new to the show. Do you want to introduce your self really quickly?
KENNETH:
Sure. Like you said, my nameās Kenneth Kalmer. Iāve been doing Ruby for seven or eight years now. I got my first Rails app up before migrations actually ended in Rails. And I fell in love with it completely and from there just tried to apply it to everything. In relation to todayās talk, that included trying to run as much Ruby in our infrastructure doing all kinds of crazy stuff and learning about daemons and how to do all these long-running tasks and processes that need to be up for months on end without any human intervention. So, Iāve just been doing that forever and absolutely love it and canāt see myself using anything else.
JAMES:
So, we need to settle it right there. He said daemon. Is it [day-mon] or [dee-mon]?
KATRINA:
Can I object? [Laughter]
JAMES:
Can you what?
KATRINA:
Object. I object, your honor. Itās [dee-mon].
JAMES:
Oh.
KATRINA:
Actually, I think in Latin, itās actually [die-mon], is what we landed on.
CHUCK:
Yeah, like maestro.
JAMES:
Yeah. But I think the official wording here, Kenneth actually gave it to us. But I say [day-mon] too, by the way. So, Iām sure youāll hear me make that slip a bunch. The word demon is an alternative spelling of daemon and is pronounced [dee-mon].
CHUCK:
So you say [day-mon], I say potato.
JAMES:
[Chuckles]
JOSH:
Letās call the whole thing off.
JAMES:
[Chuckles] Letās call the whole thing off.
CHUCK:
Anyway, so this conversation came about because Kenneth listened to our episode that we recorded live at the retreat. And I think Josh, was it Josh that said that we should do an episode on daemons when we were talking about some of the other uses for Ruby that arenāt Rails?
JOSH:
Yeah, which is I think a huge topic, doing background processing and all the stuff thatās not directly connected to user.
JAMES:
Can we get a definition?
CHUCK:
Of a user? [Chuckles]
JAMES:
No, I think I know what those are. How about of a daemon? Please do not relate it to elder gods this time.
JOSH:
Kenneth, please tell us, what is a daemon?
KENNETH:
So, Iām taking this from a presentation from Thoughtbotās Tammer Saleh. I hope I pronounced that right. Old presentation from 2007. He says daemons are less than gods, which is the OS and the kernel, but more than mortals, which is the programs. And then from the UNIX FAQ, it says a daemon process is usually defined as a background process that does not belong to a terminal session. I think that thatās the more accurate one. Itās a process that simply has no standard in and no standard out and itās completely detached. It runs in the background. The only way to get to it is through ps or activity monitor. And youāll usually see a machine is full of them doing all kinds of mundane things to keep your OS ticking along.
KATRINA:
I have a question. Could you send a signal to a daemon?
JAMES:
Yes.
KENNETH:
Yes, you can.
CHUCK:
Yes, absolutely.
JAMES:
Actually, itās very common. In something like Unicorn, for example, it often runs as a daemon and sending signals is the primary way to give daemons commands. Not to send them data, but to give them commands. So, in the case of Unicorn, you can send it a signal to stop or you can send it a signal to do its very clever no downtime reloading where it forks a new master and starts a new set of connections and then eventually cycles the old master out.
KENNETH:
Another great use for signals is if youāve got log rotation. Once oneās log rotates, finish rotating the logs, just signal the daemon so it closes the file handle to the log file and reopens a fresh log to get you rolling that way around. And you can even use signals to toggle between logging labels. So, you can have a normal logging label and give it a signal and switch it to a debug logging label to see whatās going on instead of having your daemons running production, just logging away endlessly.
JAMES:
Damn it, weāre a few minutes into this talk and Iām already learning awesome tricks. [Chuckles]
JOSH:
Okay. So, weāve said what daemons are. Theyāre background processes that are not connected to a terminal session or things that sit in the background without user interaction, no user interface. And weāve mentioned a couple of things that they get used for. What are some other kinds of things that daemons usually get used for?
KENNETH:
Mostly, Iād say performing tasks. A daemon could probably be fully autonomous. So, they could be monitoring a system, gathering stats and reporting it elsewhere. Say like New Relic has got a server agent that you can install that just sits there, or like a chef client or puppet that will sit and at certain intervals, trigger off and do some kind of work. Another use would be a daemon that sits and waits for input over a messaging medium. So, over AMQP or over Jabber, for instance, and theyāll get a command. Theyāll perform some kind of work and reply off and do something. But more often than not, theyāre just sitting there listening. 100% idle. Either at a set interval or on some external stimulus, theyāll get a job done. Does that make sense?
JOSH:
Sure, yeah. I was looking for some particular examples of kinds of things that people use daemons for.
KENNETH:
So, in the context of daemon-kit, which Iāll just introduce quickly. The elevator pitch would be its Rails for daemons. You guys can check it out or weāll have it in the show notes. Then a lot of the topics weāll cover in that context. Daemon-kit was developed in an ISP environment where people would buy hosting services or domains or email or internet connectivity. And in that context, we have different daemons running on different servers. So, one daemon would for instance, on receiving a message, itād create a mailbox for a user. Another one would be setting up domains on the DNS server. Another one would be setting up hosting. So, configuring Apache, configuring FTP access, creating directories on the web servers that are necessary, and plenty more that these would be doing. Even migrating clients from server to server, daemons would start talking to each other to get all the files packaged up, moved across, making sure things are in good state. So, thatās kind of the environment where daemon-kit was developed and took form. So, we had a lot of them and they needed to be up. People would be ordering services day and night. We couldnāt afford human intervention.
AVDI:
Can we talk a little bit about the process of starting up a daemon, what it is that makes you want some kind of library around it rather than just doing it manually.
JAMES:
Yeah, actually thatās great.
AVDI:
Because thatās an involved process.
JAMES:
It is an involved process and itās cool actually, because in the old days, one of the ways people would daemonize a process in Ruby is to load WEBrick because it had a WEBrick daemonize method. So, they would load WEBrick and call it. That makes it kind of interesting because if you just crack open the source code of WEBrick, you can look at what that method does in plain Ruby and itās pretty interesting stuff. Iāll link to it in the show notes. But go ahead, who wants to explain that?
KENNETH:
Iāll give it my best shot. So, what daemon-kit would do is do the initialization in two steps. Thereād be a pre-daemonization round and a post-daemonization round. Just for a start, daemonizing itself, and thatās kind of what WEBrick does and Ruby 1.9 has got it built-in in a process on daemonized method, it would essentially fork. The process would fork itself and exit and then fork again and exit. That kind of detaches it completely from the parent terminal. Thatās how it goes into the background. So, itās a double fork. But in that process, thereās a lot of other stuff you want to do. You might want to drop privileges, so you might start the daemon as root but you want to drop it down to nobody or to a specific user. Thereās also, if youāve got any file descriptors or sockets open, you want to close them and reopen them once youāve finished daemonizing. You might want to [inaudible] yourself into a directory for security reasons, if youāre taking untrusted inputs. You want to make sure that if somebody somehow gets your code to do the wrong thing that itās at least isolated from the system. You also what to redirect your I/Oās, so standard in and standard out. You want to close and reopen to attach either to a log file or you want to attach it to dev null. And you want to set up signal handlers for rotating log files or any other kind of stuff you want to do. You also want to have good exception handling in there, especially a kind of safety net so that if your daemon ever dies on you and youāve now lost standard in and standard out completely, you canāt get to a backtrace, that information somehow is captured and stored somewhere so that you can go back and see, āWhy did my daemon die?ā So, thereās quite a lot thatās involved in more than just the double fork.
JOSH:
One thing I didnāt hear you mention was the pid file management, which always seems to be super crazy to deal with.
KENNETH:
Yes, thatās right. I forgot about that. Thatās the[writing out a pid file and checking for stale pid files so that your code can look after itself, try to see if itās running after if a box crashed. So, itās got a hard reboot and comes back up again. Is this daemon able to, like it will find a pid file and then, is it still running? Is it not? Can it make that decision to delete it and replace it? How do you handle double ones? There was something else. Oh, itāll come back later in the conversation. Oh, the umasks. Thatās also another thing on Linux boxes. If your daemon is creating files, even if itās just log artifacts, you need to be able to set a umask so that those files are created with the right permission to be able to be read later again, which is something where if youāre not daemonizing, that stuff usually comes from the environment that started, your terminal environment when you log in as a user. But on a cold boot from an init script, the environments look completely different. You need to be able to handle those discrepancies.
JAMES:
So, this is one of the major points, I think. A lot of what Kenneth just described, the whole thing this daemonizing process is doing is detaching you from any means to interactively communicate with a user. So, you have to take a lot of steps in order to still have some kind of communication with the outside world. So for example, Josh mentioned the pid file, the process ID file. And the idea there is in some well-known location, you want to create a file and write your process ID down in that file so that if you think about commands that give you ways to start something and stop something, that stop has to know how to find what got started. And the pid fileās how that happens. You have the process ID and you can send signals to it, as we talked about before. Then setting up all this information with the logs turns out to be really key because if something goes wrong, your only means to record that somehow is probably like a log file. So, you have to set that up. JOSH:
So, does a cron job count as a daemon?
KENNETH:
No, not at all.
KATRINA:
Itās not long-running, right?
JAMES:
Right.
KENNETH:
Yes, exactly. Itās not long-running.
CHUCK:
Cron itself though is a daemon.
JAMES:
Thatās correct. Yes.
JOSH:
Case in point.
JAMES:
Itās the system that runs so that periodically, if you think of how cron works, it basically fires up some process, figures out when the next job needs to run, sleeps that long, then wakes up and runs the job. Then rinse, repeat. So itās there all the time and thatās what allows it to run jobs on some kind of a schedule.
CHUCK:
Yeah.
KATRINA:
One of the things that I found really tricky when working with daemons is that all of my mistakes seem so much bigger in a daemon. If I have some sort of memory leak, if I have a cron job, itāll run and within a seconds or minutes, itāll exit and all of that memory is released. But whenever Iām working with daemons, that doesnāt happen.
JAMES:
Excellent.
KENNETH:
So for that, you can choose to do a forking model as opposed to a threaded model. Every time you want to do your piece of work, you can just fork off a subprocess, let it do it and then die again. But itās very true. It is a very real problem and itās a really tricky one to monitor as well. We lack a lot of good tools. New Relic can give us memory monitoring over time, but daemons, itās very raw. Youāre left to figure a lot of this out on your own. So a forking pool, so to say, would probably be better than a thread pool in the very, very long run. And itās a problem that plagues a lot of daemon projects. I know the shift client as well, they have an option to specifically, every shift run when it runs every half an hour if you use that as a daemon, to fork when it runs because a badly written cookbook can completely just balloon the memory on every run. You end up with your provisioning software taking over your entire server. So yes, thatās a big problem.
JAMES:
What Kennethās just explained there, that was one of the major things I eventually understood when I was working with daemons, is that anything you do in the daemon process is basically forever. If you perform some huge database query which causes it to fetch a whole bunch of memory from the operating system, then your process ballooned by that much and itās forever. So you want that top level loop to be as lean as possible and do as little as possible. Itās basically like cron, right? All cron is doing is figuring out what to do next and then doing it. But that process, who cares what happens in that process? Itāll be dead in a few minutes. So if you use that same model where you figure out what you want to do and then when itās time to do something, you split that off and do it, then who cares what happens in that process?
CHUCK:
Yeah. And when you say split that off, what weāre talking about, and this is a good call-out to go listen to the episode we did with Jesse Storimer, but a lot of times what they do is they wind up forking off a process that goes and does whatever it is that has to be done. Then you get all the memory cleanup and stuff that Kenneth here is talking about avoiding.
JAMES:
Exit is the ultimate GC (GC == garbage collection). Never forget that.
JOSH:
[Laughter]
CHUCK:
Yeah, your operating system is really good at cleaning that stuff up.
JOSH:
Yeah.
KENNETH:
So then just to add to that, I know with all the MRIās, and I think itās still probably the case for the MRI, it never gives the heap back to the OS. So what itās allocated, it will just simply hold onto. Internally, it might free up some memory and then it might start climbing again. At one stage, [it might] decrease the stack again. But MRI will never give the heap back. The JVM for instance, which is not really good for running daemons, but you can run a blocking process but that still will eventually free up if your job gets tired, or if your job frees up the memory.
AVDI:
Iām curious why you say the JVM isnāt good for running daemons.
KENNETH:
Itās good for running background processes, but it doesnāt do the forking model. So if you want to run a daemon through Java, youāve got to, in the daemon-kit context, you can run your project in the console while you develop and youāve got access to standard out, printing out log files, pretty much like a Rails server does. It logs it to the development log and to standard out. Daemon-kit gives you the same ability. But then when you want to run it into production, you actually need to run a script that blocks so your whole process supervision model changes. You want to run it under something like God or Bluepill or run it under Monit or systemd. And it just sits there. It will never detach from the terminal. Itās a slightly different thing. But if youāve got daemons that would be data-intensive, that would fetch a lot of data and they need to give all that memory back, then that would work fantastically well.
JAMES:
Yeah, Iāve had a couple of problems with the JVM just not being very POSIX compliant. There are things that you tend to do when youāre writing daemons, things you take advantage of because of the way UNIX-like operating systems work. A good example of that is the exec call. We talked earlier about pid files and knowing where a process is. Sometimes what you need to do is you need to turn one process into another process and you donāt want its process id to change. Thatās what exec does. It lets you basically say, āFrom now on, make me this.ā But the JVM was built for it to run everywhere, so not just in UNIXy environments so a lot of times it doesnāt behave exactly as you would expect in some of these things. And Iāve filed bugs on them, JRuby, about things like this in the past. And I know theyāve corrected as much of this as they reasonably can with the limitations that the JVM gives them.
KENNETH:
James, thatās spot on. The daemon-kit embodies a lot of the UNIX philosophies. The directory structure looks similar to what your OS would look like. Just like Rails, give you a place to stash your things. That was heavily inspired from just, āIt should look like UNIX.ā When you look at Ubuntu operating system from the root, a daemon-kit project looks something similar from the root as well. It makes sense where these things belong. And yeah, the JVM just doesn't fit in so nicely with all the UNIXisms thatās in there.
KATRINA:
So UNIX features very heavily in all of this and forking and all of that. How about Windows? What does daemonizing look like on a Windows system?
CHUCK:
Windows has the concept of services and they donāt work the same way. So if you want to run it on Windows, youāre either going to have to have some kind of emulator to run your daemons or youāre going to have to write a Windows service.
KENNETH:
There is a Ruby gem, if Iām not mistaken. I havenāt checked it out in years, but there is a Ruby gem to help you create a win32 service. Iām not sure what infrastructure they give, but I think it should be completely different. Different signal handling semantics, the environments change. What does a Windows environment look like for a user? Thereās this service managed code. You need to somehow plug into the service management console. I think itās a completely different game.
CHUCK:
Yeah. But if thatās your environment, it looks like there are some pretty handy tools to do that.
KENNETH:
Yeah, it should be possible, definitely possible.
CHUCK:
Yeah.
KATRINA:
Are the [batches] very similar though in a Windows environment?
CHUCK:
The ways they work are totally different, so probably not.
KATRINA:
Okay, so it would be a different conversation then.
CHUCK:
Yeah.
KATRINA:
Okay.
JAMES:
Although some things would still apply. For example, if your service is going to be a long-running Ruby process, youāve still got to think about that, āAnything you do is forever,ā right?
CHUCK:
Yes.
KENNETH:
So no class variables.
[Laughter]
KATRINA:
No randomly generated symbols. [Chuckles]
KENNETH:
No.
CHUCK:
Iāve helped several people with their daemons. The one thing that people to run into the most or have questions about the most is getting it to start up when the server starts. Is there an approach that you like for that?
KENNETH:
Iām used to using God to boot up. So Iāll run God under system boot [label]. Itās just always been part of my shift deployments. Itās just there. Then I have God monitoring the daemon. And in daemon-kit Iāve got just a little rake file to help you generate the stub God config that you can then edit and tweak and then load into a server. So God will be kept up by [SV, whatās it], I forgot the project now. God will start on startup and it will monitor and maintain the daemons. It will watch its memory usage as well and its CPU usage all through the pid file that gets created. That gets the whole chain going. But thereās just so many ways to get that done. Iām considering looking at borrowing some code from the Foreman project which would allow me to give rake tasks as well to generate upstart scripts for Ubuntu and System V scripts for initd, to just simplify the whole lot.
CHUCK:
Yeah, I was going to say, are there tradeoffs to using God versus just adding it to your RC or some of the other options that you have there?
JAMES:
Well, if you just add it to your RC then all you really do, your resource config (Is that what it stands for?) file, it will be fired off. But thatās where the connection ends. It just makes sure something happens. But using something like God, God is going to continue to watch the process. Like Kenneth said, watch for memory overrun or whatever, you can set all that, then using the pid file it knows the commands has started up, it can kill the current version and start a new one fresh so that you donāt have to worry as much about mistakes made in the daemon process itself.
CHUCK:
That makes sense. So itās similar to using something like Monit that watches it and says this should be running and it should be behaving this way?
KENNETH:
Exactly the same use.
JAMES:
Yes. Itās the same thing except a different version, yes. Bluepill, God, Monit, those all do the same thing. If youāre on Mac OS X, Mac OS X has the launchd service which is surprise, a daemon. It is how you start and stop things like at system start time. You basically write this xml file describing your process and you end up giving it the command and the arguments for it and stuff like that. It reads those files on startup and if they request that the process be run on startup, itāll fire it up as it comes up.
JOSH:
Right. And on the typical UNIX system, that process is called initd. And years ago, Apple just changed it to do I guess something that was more suited to how they were dynamically loading code on Mac OS X. Hey, I have a slightly different direction to pursue here, and thatās how you actually go about writing the guts of your daemon. Many of us have done something simple like writing a rake task and found that the way that rake runs code makes it a little hard to TDD, to testdrive the guts of that task. So weāll pull of that out into an ordinary Ruby class or set of classes and objects and test-drive that and then once weāre done weāll just drop in a one-liner into a task and then weāre done. That seems like that would be a good way to go for building daemons. Is that a good guess on my part or are there other ways that are better for developing daemon code?
KENNETH:
No, I think thatās fantastic. Itās absolutely spot on. By doing it through the classes you get the testability and you are disconnected from the daemonization process. In a daemon-kit project typically thereāll be a lib folder which is ideally there that you drop these classes in. itās on the load path so you can get going. And these should ideally be little classes that you can just instantiate and almost like a method object and just call one method, let it do its thing and report somehow whateverās required. Then thereāll be a libexec folder and this is the place where you would put the glue between the daemon-kit and your own code. For instance, if you create a daemon thatās based on rufus-scheduler, rufus-scheduler gives you cron abilities in your own code. Youāre not dependent on the cron daemon. And one reason you might want to do that is if you want subsecond precision. Cron canāt go less than a second, oh actually I think cron canāt go less than a minute in between writes.
CHUCK:
I think youāre right. I think youāre right.
KENNETH:
So if you want sub-minute precision, rufus-scheduler uses EventMachine if itās there. Daemon-kit by default uses EventMachine. So you can get up to 250 millisecond precision in your jobs. That libexec class, there are skeletons that get generated for you. It will show you how to basically configure just your scheduling. Itās a little block that gets called and ideally all you want to do in that block is instantiate and call a method. Or you want to do that wrapping it in a forked block, if you want to get your memory back once the job is that. So that way, thereās a little seam that you can use. And thereās a generator for an AMQP-based daemon and a Jabber daemon, say if you want to send commands in over those mediums to your daemon to have it work like that. Same thing, it generates a stub for you. It shows you, this is the block thatās going to accept the message. Ideally you just want to instantiate the object with that message and the initializer calls something and either fork or not and then just be done with it. So that way, you can neatly TDD it on the side. There are test generators as well so you get failing specs or failing unit tests when you start and you just [up the races].
JAMES:
So, basically what you donāt want to do is be forking processes in every single test and trying to keep track of all of that. Maybe you want an integration suite or something that works with the full system. But it can get complicated when youāre launching all those processes and having to wait on them until they get to a certain point and all that. So thatās why what Josh said is really wise. Just separate out the work codes so that you can verify that the work does what the work is supposed to do without having the complication of it being moved through different processes and stopping you having to follow it through the pipeline.
KATRINA:
I went down a really bad path when I was doing daemons and I was using the threading model not the forking model, which was probably my first mistake. But I ended up writing tests that would use sleep heavily to even be able to verify anything. It was a nightmare. Donāt do that.
JAMES:
Yeah, and then randomly one of your tests will just fail.
KATRINA:
Oh yeah, and then you just run it again, because then it will pass.
JAMES:
Right, but then it works.
CHUCK:
[Chuckles] So I have a question related to when, and I think we touched on this, but when would you want to create your own daemon versus setting up a cron job that will run a rake task for you or using some other recurring system like a queuing system?
KATRINA:
Some of the daemons that I worked on listen to the fire hose of Twitter or the fire hose of Instagram and once that data is gone, itās gone. If you miss it, you miss it. So we actually listen to the fire hose and stuff those in a queue that could then be processed. Or I think we stuffed only the ones that we wanted into the queue for later processing.
CHUCK:
Iāll buy that.
KENNETH:
Another example might be handling inbound mail. So if you want to run a little SMTP server and people can email attachments in that you then continue taking an attachment, upload to s3, pass it onto the next thing for processing. You have got no idea when that mailās going to come in. That socket needs to be open and ready and to do its job.
JAMES:
Thatās a really great distinction right there. So there are definitely pros and cons to both approaches Chuck just mentioned. If you run a cron job, the great thing is that that process can probably just worry about itself. Itās not a big deal if it allocates a bunch of resources and gets killed by the operating system. Who cares? Whatever. Itās all going to go away and happen again later. Whereas as weāve been talking about with daemons, theyāre there forever or theoretically so have to be more careful. But thatās basically the distinction. If you can get by with just doing something periodically, then a cron jobās definitely easier. But if you need something thatās there all the time and when I turn to talk to it, it will be there to answer me, then you need a daemon.
KENNETH:
Well said.
CHUCK:
Yeah. It also seems like basically, I think the key to what James is saying is more or less, I need something there when I come to talk to it so that it can answer. And you never know when that talking to it is going to happen. A lot of these other things, if youāre just checking on something, then you can periodically pull it. So you can actually use cron. But yeah, if somethingās going to be sending it messages, āHereās this information. Handle it,ā it canāt periodically wake up and go, āDid somebody talk to me?ā
JAMES:
Daemons are used a lot nowadays in metrics gathering. So if you want to gather metrics on various things, you add a little line of code thatās like, āSend this metric now. New user signup plus one,ā something that. Then thereās usually a daemon on the other side to catch that bit of data. A cron job wouldnāt really be great for that because you would have to stick that information somewhere, like in a file or whatever, then the cron job would have to wake up, read all that stuff out, put it somewhere but meanwhile zero out the file thatās being written to while itās running or whatever. It gets complicated, right?
KATRINA:
And the question is whoās writing the file?
JAMES:
Right, exactly. Yeah. Is it various processes and the provisions are going to be right that everybody can do that or you use some kind of queuing system? But that queue has to be there in order to accept the incoming thing.
KATRINA:
Which is going to be a daemon, a server of some sort, or some process.
JAMES:
Exactly.
JOSH:
Okay, we talked about queues here. What are the typical ways that people or software communicates with daemons? Weāve mentioned message queues and we did a whole episode on that months or a year ago or something. But there are also UNIX sockets or ports or you can do signals or files. What are the sane ways of actually getting the communication going?
KENNETH:
To me, I think it depends on the kind of communication. XMPP or Blather, Jabber is a perfect way
of getting it going. Daemon-kit uses the Blather gem underneath to give you an evented XMPP client. Part of that is youāve got [poor manās] monitoring as well. You can friend your daemon using Adium or some other Jabber program and you can literally use the status of your daemon whether to see if itās running or not. You donāt even need to check emails or monitoring systems or anything. But thatās great for one to one channel kind of communication where a daemon process has a separate identity that youāre talking to. AMQP is fantastic where you might be broadcasting different command over channels and the same command might end up happening on different boxes, like heartbeat. Broadcast all your daemons and they respond back. So that would make that medium great. UNIX sockets are fantastic for local communication when youāre on the same box or you can use a TCP or UDP socket if you want to go over the network. For that, I definitely recommend using EventMachine. EventMachine for UNIX sockets as well is in daemon-kit. Itās ready for you to go. With all of this though, thatās just sending something to the daemon. You still need to develop your own little protocol. Are you sending it all snippets of JSON? Are you sending in plain text? Are you sending in some kind of binary representation? Thatās something thatās left for the project owner to solve how they want. So thereās the transport medium and then what goes in and what goes out over that transport medium. Does that help?
JOSH:
Yeah, yeah. Thatās a pretty good overview.
KENNETH:
And then, oh sorry, just to add, like James said earlier with the signals and when Katrina asked for it when she asked. Signals is more of an operations concern than the daemon doing its job. So those youāll use for shutdown safely, so start cleaning up after yourself before shutting down or log rotation or switching debug levels. Something like that is what you would use signals for. Itās not for just the running, itās more ops concern where that falls in.
JOSH:
Okay. And what about things like pipes?
KENNETH:
So that would be you can create a pipe and then you can just use EventMachine to read from the pipe in a non-blocking way so the moment data gets written to the pipe it works like a UNIX socket. So thereās the FIFO pipe. Or you can use a blocking Ruby can just read and it will block waiting for input to come in. Then you just need to make sure that the buffer size that youāre reading off this pipe is big enough or small enough that you actually get useable commands through. Those are quite easy to set up with the UNIX commands mkfifo. And it will create a special pointer on the disk thatās managed by the kernel. Your daemon can attach to it and you can write to it.
AVDI:
Yeah. Those are nice. Itās pretty low-tech but theyāre nice because you can just interact with them with regular file tools. You can cat some data to it and give it a command that way.
JOSH:
Okay. So thereās also been a lot of, if youāre doing a regular web application, thereās a lot of infrastructure and tooling people have built around deploying these things. Iām curious what the deployment cycle is like for daemons.
KENNETH:
Well, Capistrano. [Chuckles]
JOSH:
Really?
KENNETH:
Itās pretty much the same thing.
JOSH:
Okay.
KENNETH:
Capistrano. So daemon-kitās got a built-in cap recipe. It looks and behaves very, very closely to a Rails one. It depends on the pid file in the end to actually stop the daemon and start up a fresh copy. Thatās the only magic, is signaling when it is time to shut down, waiting for it to shut down, and starting it up again. Then in that shutdown I guess the only trick there really is you want your code to give it some grace, but you also want it to be able to die forcefully. So the default would be 30 seconds. If that application cannot finish doing what itās doing, you want it really just to then die. Then you can inspect the backtrace logs to see what went wrong. But weāve hooked it up very, very nicely with Capistrano and you just go. Itās as simple as that.
JAMES:
Thatās a great description right there. Having done all of these things manually, if I could give anyone one piece of advice is use daemon-kit if at all possible. Because that process you just described is tricky. You have to read the pid file and go find that process and send, it is it killed? The one that can be caught? I always get kill and term backwards. Anyways, one of them is the peaceful, āI would like you to stop now.ā
KENNETH:
Thatās the kill. [Inaudible] the term. Term.
JAMES:
Term? Okay. So you send the nice one first and then you wait. You go to sleep for a while. Then you scan the process table and see it that process is gone, if it listened to you. If it did, great, you start it up. If not, you need to send it the not nice one, the āOkay I gave you your chance. You didnāt listen to me. Now youāre just going away.ā This is exactly what your operating system does when it shuts down. It tries to close everything out nicely and then if it canāt, it ends up killing things because it has to shut down. So then you kill it. But if you kill it, they donāt get a chance to respond to that, so thereās going to be consequences. For example, that pid file that didnāt get cleaned up because you killed it before it could clean up its own pid file. So youāll need to clean that up after. So thereās just this complex set of interactions. Try this then do this, wait for this, and thereās really a lot of room to make mistakes in doing all of this. So if you get a chance, use something like daemon-kit so that you can take advantage of all of that thinking without having to do it yourself.
KENNETH:
And everything James just mentioned, you have to decide what responsibilities lie in your deployment setup and what just lies in your normal running the daemon setup. Because being able to stop a daemon from the command line and giving it grace before killing it, thatās something you want to do outside of deployment as well. So itās this whole, [itās about a huge response]. I was just skimming through the daemon-kit cab file and itās 484 lines. Thatās not the code to wait for a process to die and signal it again and eventually forcefully kill it. Thatās built into a different part of the framework. Itās quite a lot of plumbing thatās involved.
JOSH:
Interesting. Okay, so little different direction here. Are there issues with sharing code between your daemon and a web app? This seems to be a common thing that people do. Theyāre building a web app and then they start pushing pieces of it into services or background jobs. Iāve done this a bunch of times. I want to have something to send your mails in the background so that theyāre not taking time out of the request/response cycle processing.
KATRINA:
So to clarify, by sharing you mean by creating a gem for example, thatās used both places?
JOSH:
Well that would be one approach. Iām curious of what Kenneth thinks about good ways to share that code. Should they be in the same codebase? Should they be in different codebases? Does coupling the deployment of your web app and your daemon processes, is that a problem or is that an advantage?
KENNETH:
Thatās a tough one. I prefer to keep them apart. During the development, itās a schlep to keep things in sync and to make sure each thing has the bit of code it has. But I think in the long term, allowing each snippet of the codebase to focus and specialize for me has been more rewarding. I think the only thing, really, that you end up sharing is your Active Record models. Sometimes you really want completely different methods and lookups and behaviors in a daemon process than what you would want on the Rails side. The same thing goes if you split, for instance, your management app that the company uses internally from the main app serving the public. You face exactly the same problem. The same database table, it might get represented through completely different models depending on the context where youāve got the code. So I have yet to figure out the best way for myself as well. What Iāve got at the moment works. Itās just a lot of work in development. But in deployment, it works fine. I think if youāre running a daemon in a Rails project directly in the code and youāre sharing models, you would definitely need to have your deployments tweaked so that you restart the daemon process together with your main application. Because then the running code loaded in your daemon might be completely out of sync with whatās actually been deployed and what the team thinks is running live in production. So thatās a big risk. The other way you could do it is if your daemon talks to your app through a little REST API. That way, they can run, they can be even more disconnected from each other and somehow they can signal and chat to each other. The app can give the daemon commands over a different channel, AMQP. Or the daemon might have its own little Sinatra thatās just for local use. Then the daemon can talk back to the main app and they can bounce messages up and down. But I donāt know. I havenāt found the silver bullet yet.
JAMES:
I think what Kenneth just said is really important. Basically, the idea here is SOA again if you have a servers-oriented architecture. The thing I would stress there is try, try, try, try, try, āDonāt share the stuff.ā Donāt make that gem and pull it out into both places. That way lies pain. Communicate. Treat them as separate. Treat them as services. So send a message, going down to basics like JSON. Hereās the data you need to know to do your job. Then it does that job and then sends back. I would even prefer not to have them share the database if thatās reasonable. I would rather I send a message down to it, it did its thing, then if it has to it sends a message back to me and Iāll save it in my database or whatever. But obviously, it depends on what the daemon is doing and how the communication goes. But I would rather not have that shared. I would rather communicate with it. And the reason is many. Kenneth hit on a couple of big ones. If you share it, okay, now youāve got to make sure both of those running pieces are using the exact same version of everything. So kill one, youāve got to kill the other, and that kind of thing, which sucks. If thereās this background service, the point of it is that it runs all the time. So you donāt want to have to kill it because you added some new feature to your Rails app and you change that model in a way that isnāt going to end up affecting the service or whatever. You want that to be separate so you can choose when that one goes down and when the other one goes down. You can treat the two independently. And just a million other reasons. Try and try not to share. Thatās Erlangās whole thing. Send messages everywhere. Thatās how processes communicate.
KENNETH:
I can add one more potential horror story to that. If youāre daemonās using autoloading and itās not been restarted the whole time with your main app and the codebase has changed underneath, I imagine at some point, it kicks in and it autoloads a new class and that class runs in a completely different environment as to when the daemon started. That can just be a nightmare to contend with.
JAMES:
Thatās another point. If you share a significant portion of the Rails infrastructure, then your daemon just got a lot more complicated. The whole point is to keep them as simple as you possibly can because theyāre running out there in the background detached from any way to, say help, that kind of thing. You want them to be as simple as possible. So itās doing something like require rails infrastructure that violates the as simple as possible.
JOSH:
[Chuckles] Well, okay. But sometimes, daemons are doing really complicated things, right?
JAMES:
Yes.
JOSH:
Theyāre not always really simple things. Iām working on something now thatās doing basically data warehousing and it needs to have all these Active Record model classes around because thatās the implementation of the business logic that is being used to sort out all the warehousing and figuring out what information to put in the warehouse records. So thatās a pretty complicated amount of behavior in there.
CHUCK:
Yes, but depending on the behavior you may want to just pull an Active Record instead of the entire Rails environment.
JAMES:
Sure, yeah. I think thatās a great idea. Yeah, bring in just Active Record. Bring in just the models you need. But then again, I would stress Kennethās points of a lot of times what happens in the daemon is not what happens in the app. Iāve found that itās totally reasonable to keep two separate models on both sides sometimes because what this model is doing and what that model is doing may not be very related. Now if you have tons if inner relationships and stuff like that that are being used on both sides, that may not be reasonable. But definitely, youāre probably going to want to at the very minimum do a different mixin on each side because surely there are going to be some methods that just donāt make any sense from the other side and you donāt want to have to update the one application just because you changed those. And youāre right. Thatās a great example. If youāre manipulating a bunch of things in a database then obviously youāre going to have to go down that path.
JOSH:
Yeah. And then you have to worry about things like how the daemon and the app, where their coupled as. Are they coupled at the schema level in the database or do they share Active Record class model definitions? This is probably way outside the scope of this conversation because thereās almost certainly not a general answer to this kind of questions.
CHUCK:
Well thatās the thing that is so interesting about daemons in my opinion, is that we write them to do all kinds of things. The way that you talk to Rails or even a web application in general is different. Most of the time youāre doing things over the HTTP protocol and you follow a couple of general rules and with daemons it really varies depending on what you want to do and how you want to communicate with it. Thatās why this problem is so hard.
JOSH:
Yeah. One of the, I think, typical questions that everybody whoās doing any sort of daemon that works with a Rails application is what you put in the payload of the job. If you have a message queue based daemon thatās pulling job tickets off of the queue and working on them and maybe itās sending emails, user confirmation emails, something like that. I think a typical question people have to deal with is what you put in that payload. Are you putting in all of the data that you need to do all of the work to render the email and send it off to the recipient or are you just putting an object id or you have a user record, whatās the user id, and then let the demon load all of the data from the database using Active Record and do all of its work that way? Thatās a pretty big difference.
KENNETH:
My choice is definitely just the id. But that again depends. So if youāve got your email sending code living somewhere completely outside the project, not in a Resque or Sidekick worker, then it might make sense to just fill in the variables and the mail can just get fired off later and you donāt need to worry about after commit semantics. Otherwise, if you just send the id and load from a database, you need to make sure that that job or that message just gets dispatched after commit, which is probably the biggest thing that trips people up. I think to some extent, Sidekick alleviates that with its automatic retry, so the job would fail and two and a half seconds later it would pass on the first rerun. It just happens for you. And people wonder, āWhat?ā and thatās the transaction had time to commit. So I guess itās also under the load of your system. There are so many things to consider here.
JAMES:
I take the other view in that I prefer to pass the details of the job if theyāre not ridiculously large and stuff. My reasoning is that I can decouple from the database, hopefully. If I donāt have to have that connection to the database, then I consider that better. If I can treat that service as something separate entirely. So Iād rather just pass it down, what it needs to know, let it do its thing and then notify back or whatever, if it has to and decouple from that. But there are a lot of concerns there like Kenneth brought up. What if the payload is very large? Then thatās a problem hanging around in the queue. I try to write it where when Iām queuing things, thereās no danger of the queue going away. I try to write it where the queue is not the canonical source Iām relying on to stick around. So if it dies, I try to write it in such a way that Iāll be able to tell what hasnāt been done yet and I can just re-queue it the same way or something. But sometimes itās not always possible if the task is an idempotent or something. In the case of sending emails, I donāt want somebody getting a second email. So there are definitely exceptions.
KENNETH:
Disconnecting from the Active Record specifically is, yeah Iām sold James. The other thing, I was thinking with daemons, itās hidden away in Rails for you, the Active Records connection management. If your daemon is doing any kind of database interactions, you need to take a connection from the Active Record connection pool and release it. Otherwise, at some indeterminate time in the future, you'll run out of active connections which is another thing that we just forget about that Rack middleware handles for us in our day to day. So thatās another thing, being able to disconnect from Active Record just makes a hell of a lot more sense. I need to rewrite some code.
JAMES:
Unicorn has an example of that. If you look at the basic default Unicorn config, there are a couple of lines in there in the after fork handler, I think, that Unicorn supports. Thatās after it forks a process, it goes through and makes sure it reestablishes the Active Record connection correctly for exactly the reasons Kenneth just mentioned.
CHUCK:
Alright. Well weāre getting pretty close to our hour. In fact, I think weāve probably just hit an hour. Are there any other aspects of daemons that we havenāt talked about that are critical to understanding and not screwing things up?
JAMES:
Yeah, I have one more safety tip, because I never learned this until it was way too late. And itās very helpful. If youāre going to write a daemon and itās running in the background, the hardest thing to know is when something goes wrong, especially if a process dies because of an exception. You need to know that so that you can debug it. And the best to do that is to set an at_exit handler when the process starts and inside at_exit you can check Rubyās special variable, the $! variable, that holds the latest exception. It will be nil if Rubyās exiting without an exception and it will have the exception in it if Ruby is exiting because of an exception. So set an at_exit handler that checks that variable and if itās got an exception in it, throw it to the log file on your way down. So [inaudible] have the exception in the stack trace.
AVDI:
If you want to see an example of doing that, one thing you could do is read my book āExceptional Rubyā.
CHUCK:
[Chuckles]
AVDI:
But a long time ago, I wrote a tiny gem called zero-zero, which does exactly that. Basically you include it and it installs an at_exit handler which tries to save some vital information before the program dies completely. If nothing else, itās kind of a proof of concept. I would suggest just check out the gem and just take a look at the code to see what it does rather than just using it. I named it zero-zero because itās named after the zero-zero ejection seat which is supposedly capable of saving a pilot from a crashing plane even at zero altitude and zero speed. [Chuckles]
CHUCK:
Awesome.
KENNETH:
Now just to add to that, to the exceptions, you guys mentioned it in the retreatās show, is setting Thread.abort_on_exception to true. Otherwise, if some code in the thread dies, youāll never know what happened. Itās just a thread that ends up dying and your daemon sits there happily spinning along and youāre completely blind as to what happened. And similar to what Avdi mentioned, daemon-kit, I extracted from it a gem called safely which has exactly the same thing. Itās got the error handling and then error break reporting. But what it also does is the at_exit hook and then I had help from James Tucker and he helped hook in basically traversing ObjectSpace. Through ObjectSpace you can look for multiple exceptions. So any unhandled exception or even other ones that might have been handled by something like if youād have been on Blather or AMQP, so invalid protocol messages or connections dropping up and down. When the daemon exits, it writes a separate log file with all the exceptions it found and it tries to take a guess onto which the one was which could have ended the daemon, which made it die out. So you always have these backtraces that you can see all the unhandled exceptions and work with them and figure out what the error actually was.
JAMES:
I canāt stress again how important this step is. Itās one of those things youāll think about, āOh, Iāll handle it when things start to go wrong.ā Donāt do that. When a daemon separates from its environment, thatās the whole point. So when things go wrong, itās just something going wrong in this magic place that you have no visibility on and youāre not aware of what went wrong. Then think about if youāre daemon is deployed to someplace thatās different still, a different environment, then there are going to be things in that environment you didnāt think about. So you need that info captured in that log file, because thatās your only hope of being able to debug it. I actually had a project cancelled because it was a daemon that we became afraid of because we werenāt able to tell when it would die and why, because I hadnāt learned this trick yet.
KATRINA:
And on that note, that happy note, letās do picks.
CHUCK:
Good idea. Alright. Katrina, why donāt you give us your picks?
KATRINA:
Alright. I have two today. The first is a gem called servolux, which I think Iāve picked before but since itās so on topic, Iām going to pick it again. Tim Pease wrote a gem to write daemons and he handles a lot of different types of daemons. So itās set up so that itās a more modular approach. With daemon-kit, you get a lot of things out of the box. With servolux, you have to do a little bit more work on your own, but it does give you some flexibility if the Rails approach to everything being the way daemon-kit wants it to be. Anyway, servolux is great. My other one is Aral Balkan is a programmer and UI designer person. He did a conference talk called Superheroes and Villains in Design. And it is jaw-droppingly awesome. Itās about how awesome people feel when you have done design right, when theyāre using your product. Iām not going to say any more than that, but definitely go watch this talk.
CHUCK:
Okay. Josh, what are your picks?
JOSH:
Okay. Letās see. So thereās a UNIX utility that I discovered recently that Iāve been really itching to use for something real, but I havenāt had a chance yet. Iāll just throw it out there because it looks so super cool. Thatās called Pipe Viewer. Itās basically like Ruby tap for pipes. So you can pipe the output of one UNIX command into Pipe Viewer and then onto wherever else itās supposed to go.
So if youāre doing a ps and then piping that to grep or whatever, you can take the output of the first command, run it through Pipe Viewer, and it will output a whole bunch of essentially debugging information for you so that you can see whatās going through the pipe on its way to the next command. It looks really cool. Iām really dying to use it on a project, but I havenāt found a use for it quite yet.
KENNETH:
That sounds awesome.
JOSH:
Yeah. And the project looks in good shape and theyāve put a lot of good work into it. So thatās pretty cool. Then my other pick is a classic science fiction novel. I did a long airplane flight recently and I always like to have a dead tree book with me because the airlines are so insanely paranoid about letting people use their phones and things on takeoff. So I read āThe Mote in Godās Eyeā by Larry Niven and Jerry Pournelle and this is just super classic sci-fi. Itās almost 40 years old, I think. Itās in the reasonably far future, mankind encountering, or humankind I should say by that point, encountering an alien species thatās really different from us. And itās one of the best sci-fi novels every written, in many, many peopleās opinion. The odds are many people have already read it who are listening to this. But if you havenāt, itās really worth checking out and reading. Thereās a sequel to it as well that I also enjoyed. But in my opinion, nothing really can stand up and challenge this book. So thatās it for me.
CHUCK:
Awesome. James, what are your picks?
JAMES:
Iām flushed with picks right now. So Iām going to go through several here real quick. First of all, I donāt usually like to pick my own stuff, but Iāve had several people ask me if I would explain what Iāve figured out about Emacs since Iāve been playing with it. So I did do that. I held a Google Hangout recently and I tried to explain a lot of the key points of my particular configuration and how I use it. If you missed that, itās okay, because it was recorded. And itās in two videos due to a hilarious incident where I killed my own Hangout. So thereās two parts to the video and Iāll link to both of those in the show notes. But check it out if youāre remotely curious about Emacs. The other thing Iām going to link to, also mine, is I did a different talk at Lone Star this year where I played Jeopardy on stage with three contestants, Avdi Grimm, Dave Thomas and Steve Klabnik. What I did was just nothing, basically, just provided some Ruby trivia questions. What they did was make an absolutely freaking hilarious section where Dave Thomas rage quits my game in the middle of it. Steve Klabnik purposefully blows some points to troll the entire room. Itās freaking hilarious. So definitely in the spirit of wacky fun more than learning. Though I did have a couple of questions in there that seemed to stumble them. So you may pick up a Ruby trick or two while youāre watching. Anyways, that video is also now online and Iāll put it in the show notes. And finally, I probably shouldnāt say this in front of Josh but while I was procrastinating on my GoGaRuCo talk this weekend, I have this great [Laughter]
JOSH:
What?!
[Laughter]
JAMES:
Calm down Josh. I found this great game called Dungeon of Dredmor. I tweet about how I like FTL all the time which is one of those rogue like games and that itās just this crazy hard game that you die to most of the time. And somebody responded to one of my tweets and said you should check out Dungeon of Dredmor. So I finally did that this weekend and oh my gosh, this game is awesome. Itās Diablo-esque in that you grab a character and take off into the dungeon. The things this one has going for it, first of all thereās just a massive amount of character abilities from vampirism, your typical swords and shields and armor, then magic and [inaudible] stuff, to piracy, to crazy stuff like rogue scientists and just all kinds of crazy abilities. So thereās lots of combinations and synergies that makes dying awesome, because then you just go back and youāre like, āWhoa. I want to try this.ā And thatās cool. It has a really neat turn-based thing. The whole thingās turn-based, but it feels real-time. Youāre just walking around in it, but then when things start to go horrible bad, you realize that every step you take, every potion you drink, all that, thatās one turn. So you use something then the bad guys get to use something. So it lets you slow it down to a strategy game pace and think your way out of it, which I really enjoy. And finally, the humor in it is freaking hilarious. I cannot stress this enough. This game is a blast. It has tons of pop culture references in it. Indiana Jones, if you start off with the archeologist ability, you have a fedora hat that turns out to be one of the great items of armor for a starting level character. If you get your perception up high enough, you get lasers that shoot out of your eyes. Your eyes just get so good they get lasers. Itās totally hilarious. [Laughter]
JAMES:
Awesome game. You have to check it out. Those are my picks.
CHUCK:
Awesome. Avdi, what are your picks?
AVDI:
First of all, Iāll second servolux as I always do and also Mote in Godās Eye. Great book. So Iāve been revamping my whole publishing tool chain lately, both for the launch of Confident Ruby and for the book that we, the Rogues, are working on. Thatās involved throwing some old tools out, slotting some new tools in. Anybody whoās done eBook publishing, the tool chain usually winds up something like this. Usually you have part of the tool chain which whatever you start out with, you wind up with html and then the html goes into your epub version and into your Kindle version, possibly into a website version. So you have this whole html chain. But then youāve got this parallel chain, because there are still lots of people who want pdfās. Especially, youāre going to need pdf if youāre ever going to print it. So youāve got this parallel chain for pdf which is a different universe, because usually youāre using either LaTeX or maybe youāre using DocBook to XS-LFO or something like that. Either way, itās a completely different language from the html and CSS that you used to style all the other versions of the book. So you wind up doubling your time working on styling and layout for two different, these two parallel universes. And itās a huge waste of effort. And some of these things just are not pleasant to work with. I havenāt done a lot with XS-LFO but LaTeX certainly is a gigantic learning curve and often makes easy things surprisingly difficult. So when I redid my tool chain I decided to see if I can get away from all this. Iāve been using html as the universal intermediate format and then using a tool called Prince XML for the pdf output this time. It is a commercial tool. It is not free. But it is pretty freaking amazing. Basically, what it does is it will take html and CSS and have really, really good CSS3 support, which includes all of the CSS3 print stuff. So you can actually do a really good print layout including stuff like where the page breaks would fall and if it should always put a particular kind of page, break the pages so that that page should be on the right hand side when you open the book. And the leaders and the footers along each page and automated generation of page number references, all that kind of stuff. Plus it does the Knuth [hyph] layout, text breaking and hyphenation algorithm, to make printed text look really, really good. And you can just take the same html source and the same CSS and add some print CSS and toss it into Prince and you get a great looking pdf. So itās a really nice tool. Sure, there are some other tools out there, some open source tools out there that will do this as well, but theyāre basically as good as hitting the print button from your browser, which as you know is not that good. So now the downside of Prince is that it is $500 for a personal license. But thereās another cool tool out there called DocRaptor which is the software as a service version of Prince XML. So you sign up with them and you can send them RESTful web requests with your document and they will send back the pdf formatted version. And that is very reasonably priced. So both of these tools together have been really incredibly helpful in redoing my tool chain. I guess I went a long time with that, so Iāll just one more. Another thing that Iāve been playing with as Iāve been doing this tool chain is a little tool called XMLStarlet, which is just a nice little command line tool for dealing with XML in many different ways. You can do validation, you can clean up your XML, you can select just a little part of it using an XPath. Itās like sed and awk, only for XML. Pretty cool.
Alright. Thatās enough for now.
CHUCK:
Awesome. Alright, well Iāll go ahead and do a couple of picks. So Iāve been getting my stuff organized. I keep changing the way I do this. I guess Iām just not happy with the way that I organize things. But a few things that Iāve been using lately to get things organized is, one of them is Evernote. Iāve recently started putting all of my, Iāve been trying to go paperless. And I guess thatās another pick. So thereās the MacSparky field guide. Itās called Paperless. Itās a book and videos and stuff and it talks about different techniques for basically moving away from keeping a whole bunch of papers in a file. So Iāve been scanning all of my papers using a ScanSnap S1300i which is actually a little portable scanner. Itās really, really nice to have and I can actually take it on trips, scan the receipts and just throw them away, which is also nice. And then Iāve been putting it into Evernote. So Iām going to pick the scanner and Evernote as well as the Paperless book. And a few other things that have come in handy, I use SaneBox for my email box and Iāve been trying to follow GTD so itās nice to have something that just goes in and filters out all of the stuff that isnāt critically important. Then I can either move the stuff out of my inbox into action or follow-up. And then I just routinely go through the action stuff and do the stuff in the action stuff. In the action folder, sorry. Then I go through the follow-up folder and just make sure that Iām keeping up with the people that I need to keep up with for stuff. So Iām also going to pick Gmail and SaneBox. And those are my picks. Kenneth, what are your picks?
KENNETH:
My first one is the presentation I mentioned in the beginning for the definition of what a daemon is, is the Angels and Daemons presentation by Tammer Saleh from Thoughtbot. Thatās just a great glimpse of the history where we all started on this quest for figuring out how to daemonize your code. So itās really nice to just get into the guts and see whatās going on. For the second pick, Iām going to pick Rubyfuza. Itās a Ruby conference in Cape Town in February, first Thursday and Friday of February. Itās a fantastic conference. Itās well worth the trip to come visit South Africa. For my third pick, Iām going to pick a music festival here called Oppikoppi. Itās also inside Africa. Itās in August, first weekend of August. Itās the only festival in the world where you can have your beer delivered by drone. It is really, really fantastic. Given that and five stages of amazing bands. Then further [off tech] is two other podcasts. 99% Invisible. Theyāre from San Francisco. And then Radiolab from New York. I find both those are just great for listening to something else, opening your mind, hearing about different stuff people do, different adventures people go on. Itās just a fantastic way to just be inspired. So those are my picks.
JAMES:
Plus one on those two podcasts. Theyāre great.
KENNETH:
Absolutely.
CHUCK:
Yeah, they are. I listen to them as well. Alright, well letās go ahead and wrap up the book [Chuckles] the book. [Chuckles] Letās go ahead and wrap up the show. I was reminding myself, mention the book club book. Weāre going to be reading Confident Ruby by Avdi Grimm. That will be, I think the beginning of October. Anyway, go pick it up. Itās been a good read so far and weāll catch you all next week.