750words Archive

Starting the Gardening Year

It’s time to start working on the garden. Actually, a little past time. I planted a double-row of peas about ten days ago, as well as lettuce, parsnips, radishes, and carrots in the little bed in the grotto. The cold weather last week made that seem too early, but those things should still come up.

I have a lot of leftover seed that germinated okay last year, but it might be iffy this year. So I wanted to get some things out there early to see how they come up. I may also need to germinate some seeds in paper towels, to see how they do before planting them out.

Other plants already started: mint that I got from my mom over the winter and started in a pot, and sweet potatoes that I started from a couple potatoes that had sprouted in the basement. It’s still a couple months before the sweet potatoes can go out in the garden, but they should have plenty of roots by then.

We should have marshmallow, hyssop, and toothache plant as perennials in the herb garden. There may be catnip by the grotto, but I think the cats wiped it out rolling around on it last year, so I expect to have to start that again.

The walking onions around the grotto are starting to green up, and the strawberries that survived last year look good and need to be weeded around. So quite a few things are already underway. Right now, I have two things to get figured out. First, where I’m going to get enough mulch to cover all the garden spots. If I’m going to use the mulch method this year, I’ll need enough to bury the gardens in several inches of mulch. Alternatively, I could use paper or cardboard, but I’ll still need enough mulch to put on that and hold it down in the wind. One thing I’m thinking of is to buy a half-dozen round bales of hay, and bust two of them up on each garden spot. That would certainly do it.

The second thing is to get seeds ordered. So before that I need to go through the leftover seed and seed saved from last year and see what else I need to add to that. I don’t think there are too many things I’m missing, but I always like to add something new. I had really good luck with the watermelon last year, better than I ever have before, and I grew Moon & Stars for the first time, so I want to make sure to get that again.

Oh, a third thing: it’s time to start cleaning out the chicken house and spreading it on the gardens. That will help with the mulch situation too.

The pole at one end of my trellis finally rotted through at the bottom, so I need to replace it. When I put that in seven years ago, I used ordinary pine lumber, so I didn’t think it would last more than a couple years. It’s worked out pretty well. Have to weave new twine on it for the year, but that doesn’t need to be done until something is ready to climb it, probably not until a couple months from now.

I may have to put some fence around at least one of the garden spots. The chickens really worked on the cabbages there last year, devouring a couple of them entirely, which was strange. I won’t be planting cabbage in the same spot, since I rotate things through the gardens every year, but that’ll be something to watch out for. I like letting them roam around the gardens eating bugs, but I don’t need them eating my vegetables.

I want to get some permanent fruit trees going this year. I started a couple grapes and a couple raspberries last year, but none of them survived. Need to get better stock from Stark’s this year, instead of the cheap ones off the shelf. The asparagus bed is mature now (could be bigger), and the strawberries are getting started, so I’d like to keep adding another long-term planting each year. A small orchard of apple, pear, peach, and cherry trees would be great.

As far as annual stuff goes, it’ll be the usual. I think I’ll do videos every couple weeks again this year, since that was a good way to keep track last year. I referred back to those a couple times to find out when I planted something or what variety where. Probably not until there are some plants coming up to see, though.

Hammer All the Cores

My current workstation has 8 CPU cores (each core can handle a stream of instructions independently, so it’s more-or-less like having 8 CPUs – 8 different “brains” that can each be running its own thing at the same time). My last computer had 2, so I’m guessing my next one will have 32. They seem to be hitting a wall on how fast a single CPU can be, so the next best thing is to stack more and more of them together.

The only problem is that most programs can only use a single core. It’s a lot more complicated to write a program to spread its work across multiple cores, and some programs couldn’t take advantage of that anyway. So there are many times when I’m running a program that’s working one core as hard as it can, while the other seven are mostly idle. The nice thing about that is that one heavy program doesn’t bog down the system, since other programs can sail along on the other cores. Most of the time, that’s great. But if you have a task that you want to complete quickly, it would be nice to spread it across more of them.

For instance, I recently needed to increase the volume on a series of 15 podcast files. You can do that with ffmpeg, using a command like this:

ffmpeg -i file.mp3 -vn -sn -dn -af volume=10dB new/file.mp3

That reads file.mp3, ignoring the video and subtitle streams, and writes it into the same filename in a ‘new’ subdirectory, bumping up the volume.

But it takes a minute or two per file, and I have 15 of these files, so I don’t want to type that command for each file every couple minutes. So the simple thing to do is to wrap a loop around it:

time (for i in *.mp3; do  ffmpeg -i $i -vn -sn -dn -af volume=10dB new/$i  2>/dev/null; done)

A couple of new things here. First, I wrapped the whole thing in a ‘time’ call so it would tell me how long it took. I also sent the output of ffmpeg to /dev/null, so it’s not filling up the screen. The loop runs ffmpeg for each MP3 file, substituting the filename for $i in the command.

But here’s where I run into the problem I started this post about, because it runs one command at a time, and the whole thing took 29 minutes. How could I run them in parallel? Well, an easy way is to run them in the background, so the for loop won’t wait for each one to finish before starting the next. Like this:

for i in *.mp3; do (</dev/null ffmpeg -i $i -vn -sn -dn -af volume=10dB new/$i 2>/dev/null)&; done

The new thing here is that the & puts the ffmpeg command in the background. I give ffmpeg its input from /dev/null, because otherwise when you put it in the background, it stalls and complains because it’s watching for input from standard input (the keyboard, usually). I had to remove the time call because, since this puts the commands in the background, it finishes immediately. So I timed this manually, and it took a little over five minutes.

That’s a big improvement, but now there’s a new problem: I’m running 14 processes that can each use one CPU to its limit, but I only have 8 cores, so they’re having to share. That’s not a problem at this scale, because FreeBSD multitasks very well, and I didn’t have anything else important going. But what if I had a hundred, or a thousand files? Running that many ffmpeg processes in parallel could bring a machine to its knees.

So I’d really like to limit how many run at once, putting them into a queue so that one starts after another finishes, but a certain number can run at once. Now, there are programs that are designed to do just that, and I could install one of them and learn how to use it. But one thing I like about Unix is that, if you know the basic tools, you can put them together to do complicated tasks for unexpected tasks that come along. It’s like when you’re working on a car and the shop manual says, “You will need a door handle clasp removal tool to remove the door handle clasp.” Yeah, right. I’m not buying a tool that I’ll only use once. I have pliers and screwdrivers; I’ll get it off just fine, probably after some swearing and bloody knuckles.

So my inclination is to look first to the standard tools, and there’s one that fits the bill here: xargs. Xargs is a great program that takes a stream of text input and passes it to a program as arguments. I use it in combination with find every day in commands like this one that searches through a tree of files for a phrase:

find . -type f -print0 | xargs -0 grep phrase

But xargs also has a queuing ability, because you can tell it how many times it can run its argument at once. So I dropped the for loop (since xargs effectively does its own loop), and rewrote my command:

time (echo *.mp3 | xargs -n1 -I %% -P6  ffmpeg -i %% -vn -sn -dn -af volume=10dB new/%%  2>/dev/null)

I was able to bring back time, since this doesn’t background anything. The arguments to xargs tell it to take one argument from the pipe at a time (-n1), replace %% in the ffmpeg command with that argument (-I %%), and run up to 6 processes at a time (-P6). This took just over 7 minutes, and it never pushed the load average over about 6.5, which means I still had a CPU or two available for doing other work without getting slowed down. If I let it run 8 at a time, it might shave another minute off.

So in the final analysis, I got a 4-times speedup on the task, using very basic tools available on any *nix system, without any complicated programming effort. And I learned a little something about xargs in the process. Good deal.

My 750 Words a Day

I’ve been wanting to do more writing, but have had trouble getting in the habit. I got some inspiration recently, though, from a podcast series done by Mike Nelson of MST3K and Rifftrax fame, where he and a friend read and discussed Ready Player One, the best-selling book that’s being made into a movie. I haven’t read it, but based on the excerpts they shared, it sounds as if Tommy Wiseau (The Room) and James Nguyen (Birdemic: Shock and Horror) co-wrote a sci-fi novel. If something that bad can sell millions of copies, I have no excuse for not getting words on paper.

So I’m setting myself a requirement of 750 words per day, which I will be posting here. That seems to be a common limit people use. No particular topic for now, just whatever I can think of. If I can’t think of anything, I’ll write about how I can’t think of anything.

A tip I recall from Piers Anthony’s autobiography: when he was writing (with pencil and paper, back then) and got stuck, it was usually because his mind wandered to something else. So he would just put an open bracket and write about the other thing until his mind came back to his original story, then close the bracket and go on. When writing the final manuscript, he would skip the bracketed sections, but sometimes he would find ideas for other stories inside those brackets. Since I’m writing in org-mode, I can go one better: distracting ideas can be captured into separate tasks which will come up to be refiled later.

I’m always tempted to edit as I write. Most of my blog posts and other writing online are first and last drafts, except for spell-checking and very minor editing. Although I went to what was considered a good school, we really didn’t do much writing that I recall. Most papers were 500 words or so, which I could plan out in my head and then slap down on paper in one go; and I’m still writing that way, editing at the end of each sentence, or even mid-sentence. That’s not really very efficient, which is probably why it’s tiring and seems daunting to start. So I’m going to make myself just write and not try to edit on the fly. This writing isn’t for anything, so it doesn’t have to be perfect, and if I happen to write something with potential here, I can come back and edit and shine it up later.

I’m writing in org-mode, an organizer mode for Emacs that does a whole lot of other things. I should write more about org-mode itself, because it’s great. For this project, it’ll allow me to set a reminder which pops me right into this project. When I finish an article, I’ll hit C-c C-e H H to publish it right to my blog. It’ll be easy to search for ideas later, and it’s already set to back everything up with version control. I also have it on my phone, and though that’s not a practical place to write, I can capture topic ideas there and import them to my workstation later.

I’ve been assembling a list of ways to think of topics. One interesting idea comes from James Lileks. He found a box of old matchbooks that someone had collected from motels across the country. So he created a character called Joe Ohio, a traveling salesman. Each day he would pull out a matchbook and write for 30 minutes about Joe visiting that location. He came up with some pretty good stories, and was talking about turning it into a novel, though I don’t think that ever happened.

So ideas can come from anywhere, but they have to come from somewhere. I think I have enough ideas and ways to generate ideas that I shouldn’t have the “I can’t think of anything to write about” excuse. With gardening season coming up, there’s always that. I also need to write for some work projects, so I could do double-duty on some of those.

I did the podcast thing for a while last year, and I might get back to that when the weather warms up. It was nice to sit outside in the shade, away from my desk, for that. It’s probably not going to be my thing, though. To keep from outright rambling, I needed to have some kind of outline in place, much like I’d do in my head before writing a post, so it wasn’t the labor-saving exercise I thought it would be. It turns out talking into a microphone extemporaneously is a skill that requires practice, not something just anyone can do off-hand.

750 words is a lot of words, when you actually pay attention.