Why would you want to see what gems depend on a specific gem? I used this technique when the mime-types gem got some huge memory savings. We wanted consumers of the mime-types gem to update their libraries to take advantage of the savings. I opened pull requests for the top few gems.
You could use this to proactively reach out to other libraries to test out a pre-release of a gem. You could ask other library authors for feedback on an issue or a PR. Having a context around the ways that people use a library can help library maintainers to make better decisions and cause less headaches.
In the sprockets case, I was curious in how the major gems consume sprockets. I have some ideas on ways I can refactor sprockets internals to make it easier to work with, but I want to verify no one is using an edge case of one of the existing APIs. If you were wondering here's the list of all the gems that have ever dependend on sprockets:
In a recent patch we improved Rails response time by >10%, our largest improvement to date. I'm going to show you how I did it, and introduce you to the tools I used, because.. who doesn’t want fast apps?
In addition to a speed increase, we see a 29% decrease in allocated objects. If you haven't already, you can read or watch more about how temporary allocated objects affect total memory use. Decreasing memory pressure on an app may allow it to be run on a smaller dyno type, or spawn more worker processes to handle more throughput. Let's back up though, how did I find these optimizations in Rails in the first place?
A year ago Heroku added metrics to the application dashboard. During the internal beta, one of the employees building the product asked if they could get access to my open source app, codetriage, because it was throwing thousands of R14-out of memory errors a day. This error occurs when you go over your allotted RAM limit on Heroku (512 mb for a hobby dyno). Before metrics, I had no clue. As the feature was made available to customers, they became acutely aware that their apps were slow, used lots of swap memory, and threw errors right and left. What should they do to get their apps back in shape?
Initially we recommended reducing the number of web worker processes. For example if you were running 3 Unicorn workers (our recommended webserver at the time) we might suggest you decrease it to 2. This solved the problem for most people. Exposing the RAM usage helped tremendously. Still, customers reported "memory leaks" and overall they weren’t happy with their memory use. When our largest customers started to ask questions, they landed on my desk.
I'm responsible for maximizing Ruby developer happiness on Heroku. This can mean writing documentation, patching the buildpack to stop pain points before they happen, or working upstream with popular open source libraries to resolve problems before they hit production. The longer I look at slow code or code with a large memory footprint, the more I see these things as reproducible and ultimately fixable bugs. As I was seeing issues in customer's reported apps and in some of my own, I went to the source to try to fix the issues.
$ derailed exec perf:objects
I ran this benchmark against my Rails app, identified a line that was allocating a large amount of memory, and refactored. In some cases we were using arrays only to join them into strings in the same method, other times we were duplicating a hash before it was merged. I slowly whittled down the allocated object count. Allocating objects takes time. If we modify an object in place without creating a duplicate, we can speed up program execution. Alternatively, we can use a pooled object like a frozen string that never needs to be re-allocated. The test app, codetriage.com, uses github style routes which requires constraints and a "catch all" glob route. Applying these optimizations resulted in a 31% speed increase in url generation for a route with a constraint:
The routing improvements combined with all the other savings gives us a speed boost of more than 10%. The best part is, we don't have to change the way we write our Rails app, you get these improvements for free by upgrading to the next version of Rails. If you're interested in where the savings came from, look at the individual commits which have the methodology and object allocation savings for my test app recorded.
Working with Rails has made me a better developer, more capable of debugging library internals, and helped our Ruby experience on the platform. Likewise having a huge number of diverse Rails apps running on the platform helps us be aware of actual pain points developers are hitting in production. It feels good when we can take these insights and contribute back to the community. Be on the lookout for the Rails 5 pre-release to give some of these changes a try. Thanks for reading, enjoy the speed.
If you like hording RAM, maximizing iterations per second, or just going plain fast follow @schneems.
It started screaming for life. Sucking in air and yelling out with a beautiful pain. I couldn't stop smiling.
I didn't know what paternity leave was until I was already there. We spent months taking classes about labour and raising a newborn. We read books, and grilled friends for tips and product recommendations. Rarely if ever, did conversation turn towards paternity leave. Of everyone I talked to, I was the only one that actually had an official "paternity leave", everyone else had "vacation". All the fathers I spoke with took at least a little time off, though most seemed to only be able to muster 1 week out of their accrued bucket. In comparison, my company offered me 4 weeks of paternity at 80% pay.
Most people can conceptualize a maternity leave. We understand that it is necessary for the Mother's body to heal, and for nursing a baby. What exactly does one do during a paternity leave? It's basically vacation for the Dad, right?
We've got a system set up where my wife is in charge of feeding the baby, and healing. I try to tackle everything else in the baby realm. This means dressing, changing, swaddling, and cleaning. Before we go out, I pack the diaper bag, and strap the baby into the carrier. I try to anticipate things our baby needs and accomplish them before they're too urgent. I started doing this for my wife, in order to take the load and worry off her, but it had an unexpected benefit - a closer bond with my son. I've always thought newborns were boring, but having one changed my mind. Every day is a small, if hardly noticeable growth, that is only visible through constant vigilance.
My schedule looks like this: I usually go to bed at around 10 depending on how much sleep I got the night before, but sometimes as early as 8. We swaddle, change, and nurse the baby, and put him in a bassinet by our bed. Every 1~2 hours he'll wake up to be fed. My wife feeds him, I change him, burp him a little, and do any necessary clothing changes. I try to see to any needs my wife has if I can. The biggest one is refilling water (I highly recommend a thermally insulated spill-proof water bottle like camelbak podium). Best case scenario: we go back to sleep for a few hours. Worst case: a few minutes. I try to combat the fatigue by napping during the day, or by going to bed earlier and not getting out of bed until later. Once I get "up" I make coffee and bring my wife food when she's ready. We are lucky enough to have family staying with us, so I don't have to prepare meals or clean.
It's hard to say what I do during the day. We still go through the same changing-feeding schedule, but it doesn't seem as bad as when you're not having to wake up. Even with naps and and early bedtime, I often find myself so drained that I can't really focus on a task for too long. I had anticipated more downtime during paternity leave. We purposefully didn't watch season 3 of "House of Cards" so we could binge it during this time, but we've not even watched the first episode. The best way I could describe life when we're awake, is things seem to take 4x as long. Before, leaving the house took 15 minutes. Now it takes 1 hour. I've taken the opportunity to do some basic handy-person tasks in my backlog, such as changing my car's cabin air filter, and doing some work on my bedroom vents so the baby won't be cold at night. Even so, I find it difficult to heavily focus on one task for very long. Even after a good night, when I'm not exhausted, my attention is always split. I always have to be ready to drop what I'm doing and switch to baby gear. While I could imagine myself already back at work for a week, I can't imagine it being healthy for me, my relationship with my wife, or my employer. In an industry chalk full of burnout, I can't imagine anything more burnout inducing than showing up at work sleep deprived, and worrying about your little one when someone is demanding you to stay late to file your TPS report. My time away has been no vacation, but the ability to focus my life's energy on a single undivided task has been greatly rewarding.
One of the hardest things about taking time off has been acknowledging that I can be replaced in my company, and taking active steps to make that replacement easier. I think this is a large reason many men don't take a long break after a child's birth even when they can. They think, "How will this place run without me? I'm really needed here". It feels great to be needed by a team, or a department, or a company. It can be hard to feel needed when you're deep in a diaper full of shit. Don't make your partner pull unnecessary double duty if they don't have to.
Since pregnancy, I've started looking at "job security" a little differently. If you're so irreplaceable, how could someone ever promote you? The most critical members of the team aren't those that single-handedly hold up the keystone, but those that lay down pillars of brick to help prop up their teammates.
A large portion of my job is supporting customers, so during the months before I left, I took deliberate time to document problems and fixes so others on my team would know how to handle them. The kind of things you don't bother writing down because you know them so well. After publishing several documents and sharing with support, I was surprised to find it helped me even before going on leave by decreasing ticket count. With a hard deadline and a clear set of handoffs it's hard to fudge things. I think my wife did a much better job preparing for the leave. She hired 2 employees and successfully delegated most of her job to 4 separate employees. She frequently says to me, "Getting pregnant was the best thing that ever happened to me professionally." Even if you're not going to have a kid, I think it's a good thought experiment the next time you request a pay raise. Talk about all the ways you've made yourself redundant. If you got promoted today, could someone take over your job? Why, or why not?
P.S. I've only ever had one person ask me if I was going to go back to work after the baby (yes), versus the countless numbers that asked my wife (yes). If you want to ask maybe try "Are both of you going back to work?" or "what's your child care plan after leave?" The best intended questions come with some of the worst pre-defined judgments.
Honestly there are too many things to share to make this a very focused post. I really wanted to talk about what it's like to have some time to spend bonding with your partner and a new child. For me it's been incredibly empowering. I can't imagine coming home from an 8 hour day, then having to wake up every hour, change a 'poopy' diaper, and not feel any resentment. My time off came with the opportunity to grow with my family instead of us falling apart. If you've taken paternity leave or know someone who has, please encourage them to share their story-both good and bad. If you're a male who is planning to have kids, ask your company if they have paternity leave or if they would consider adding the benefit. I think that men should take pride in being involved with their family. We can be incredibly involved in raising a child, even from an early age.
Every program wants to live forever. What happens when a program is forced to exit before it’s done running, and why would we want to do that?
In this post we take a look at how Unix uses signals to tell processes when and how to shut down. We will also take a look at how Ruby handles these shutdown signals and how you can ensure your program will do the right thing.
I’ve never met a developer who complained about code getting faster or taking up less RAM. In Ruby, memory is especially important, yet few developers know the ins-and-outs of why their memory use goes up or down as their code executes. This article will start you off with a basic understanding of how Ruby objects relate to memory use, and we’ll cover a few common tricks to speed up your code while using less memory.