Thursday, May 16, 2013

Taming the Chrome Memory Pig

As I wrote in my last post, I've had problems with memory swapping on my Ubuntu system. Swapping is when programs and data are taken out of RAM and put on disk. Systems do this so they won't run out of RAM. Ubuntu, however, ships with a fairly aggressive swapping strategy.

The way I fixed the problem was to reduce the swappiness configurable in Ubuntu but, as I was analyzing that, I discovered that both Xorg and Chrome were eating a great deal of memory. As far as I can tell, Xorg bloats due to applications not releasing display memory properly. I figure there's not much I can do about that.

Chrome, however, was another matter. I found a Chrome plugin called OneTab. This product claims to reduce Chrome memory usage by 95%. It accomplishes this by collapsing all the open browser tabs down to one filled with links which, when clicked, restore the tab with no data loss.

It actually seems to work. The only problem is that restored windows don't retain their browser history so you can't use the back button to return to a previous screen after restoring a window. Still, when Chrome has your system crawling, OneTab is a good alternative.

Tuesday, May 14, 2013

Ubuntu Swappiness

My desktop has been running slow for a while. Granted I have a PoC computuer with only 4GB of RAM but it should suffice to run Ubuntu. The disk seems to grind a lot which usually indicates a lot of swapping. Since the wife and I use different browsers I have to assume one is swapped out over time. This seems odd since the system monitor shows swap space being used even though I have plenty of RAM left.

Enter the swappiness configurable. Here's a cut and past from the Swap FAQ.

What is swappiness and how do I change it?


The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and onto the swap disk. Because disks are much slower than RAM, this can lead to slower response times for system and applications if processes are too aggressively moved out of memory.
  • swappiness can have a value of between 0 and 100
  • swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as long as possible
  • swappiness=100 tells the kernel to aggressively swap processes out of physical memory and move them to swap cache
The default setting in Ubuntu is swappiness=60. Reducing the default value of swappiness will probably improve overall performance for a typical Ubuntu desktop installation. A value of swappiness=10 is recommended, but feel free to experiment. Note: Ubuntu server installations have different performance requirements to desktop systems, and the default value of 60 is likely more suitable.
To check the swappiness value
cat /proc/sys/vm/swappiness

To change the swappiness value A temporary change (lost on reboot) with a swappiness value of 10 can be made with
sudo sysctl vm.swappiness=10

To make a change permanent, edit the configuration file with your favorite editor:
gksudo gedit /etc/sysctl.conf

Search for vm.swappiness and change its value as desired. If vm.swappiness does not exist, add it to the end of the file like so:
vm.swappiness=10

Save the file and reboot.

I'll try a swappiness of 10 and report back here in a few days if performance improves. The instant I changed it the disk stopped grinding so I am hopeful this will fix my problem.



Sunday, May 5, 2013

Setting up Ubuntu as a Media Server for Xbox and Android Devices

Recently we cut the cord with cable, relying solely on the internet for our entertainment. The reasons were many but not going deeper in the financial hole each month was a strong motivator. Also, our Wii system broke so we needed a replacement media console for Netflix and Hulu. My son wanted an Xbox we decided to go down that path.

The Xbox is a beefier gaming console and now that Zack is older, he wants to play more of the shoot-em-up games which the Wii doesn't support well. The Wii also does poorly with flight simulators, which Zack loves, so I decided to bite the bullet and spend the $300 for a new system.

I was pleasantly surprised to find a pretty sweet deal on new Xboxs. You can get one with 256 GB of memory for $99 if you sign up for 2 years of Xbox live. Since I was going to need the live account anyway, it seemed like a pretty cheap entry point.

What we had:
AT&T cable with a 12 MB internet pipe and phone, Netflix, Hulu, Amazon ~ $200/month

What we have now
25 MB internet pipe, phone, Netflix, Hulu, Xbox Live ~ $80/month

So we're saving around $120 a month. Over a year that adds up.

Before I start on the technical details I have to add a caveat: the wife isn't happy with the number of steps it takes to watch her shows. Some of them I have to find on either Amazon, Hulu, or Neflix. Others I find them on YouTube or other media sources. Still, we only watch a few shows each week so I don't consider this a burden. I think my wife feels differently.

Also, if you aren't going to use your PC as a media server that plays content you've stored there, then you really don't need to read much of this article. Everything I've listed above is well documented and pretty easy to set up. If, however, you want to use your computer as a way to serve up music, photos, and videos then read on.

Also, this is one area where windows is probably a better solution than Ubuntu. I have Ubuntu doing well but the Xbox is a Microsoft product and thus integrates with Microsoft windows really well. I've read more than one post stating people basically gave up and bought a cheap computer to sit next to their gaming console.

So, for you Ubuntu and Mac users, read on.

Recommendations:
  • This assumes you already have a broadband internet connection. Most plans these days will do but the ideal size of your internet pipe depends on how many machines you're going to connect. 12 MB download speed should be sufficient for anything. 
  • For the best experience, I suggest an HDTV using an HDMI cable for connection between the Xbox and the TV. 
Details
  1. Go to the $99 Xbox page - you'll have to sign up for an Xbox Live account for $15 a month then take the coupon to one of the participating stores (Microsoft, Best Buy, GameStop, Toys R Us, or Walmart) to redeem the coupon. You'll have a choice between a larger disk drive and a Kinex system. I recommend more drive space since the 4GB that comes with the Kinex isn't enough to store much.
  2. Purchase your system and install it at home. I would leave it outside of any cabinet, this system runs a hot.
  3. Set up your Amazon, Hulu, and Netflix accounts - its fairly simple. ( you can stop here if you aren't setting up your PC as a media server)
  4. Go to the PS3 Media Server Download page. You'll find links for Windows, Mac, and Linux. 
  5. For Linux, you'll see a pms-generic-linux-unix*.tgz file. Download this and extract the contents to a directory of your choosing.
  6. You have a choice of running the server by hand or setting it up as some sort of service. I still run it by hand but created a script on my desktop to run it. To run it the first time open a terminal window, cd to your extract director and run ./PMS.sh. You should see the window below. 
  7. You'll need to go to the Navigation/Share Settings tab and tell the PS3 Media Server what directories it can access.
  8. Add your Video, Picture, and Music directories here.
  9. I've found the transcoding video media streams doesn't seem to work well from PMS. My devices time out before my POC computer can serve the first of the stream. My advice is to only stream videos your device (Xbox or Android) that they can consume natively. Therefore, go to the transcoding tab and add mp4 and mpv to the 'skip transcode' box. 
  10. I'm not sure if this is needed but I would Quit the PMS and then start it back up again. 
  11. Now go to your Xbox and access the System Media Player under TV and Video. You should see your PMS server available. Now navigate to your content and enjoy!
Diving Deeper

Now for some of the fiddly bits. The MKV format is popular for downloadable internet content but Xbox doesn't support it and, if I read the Xbox support site correctly, they have no intention of supporting it.  A product called HandBrake solves the problem.

With HandBrake I can convert the mkv files into mp4 format which the Xbox reads well. To install on Ubuntu run the following commands in a terminal window
sudo add-apt-repository ppa:stebbins/handbrake-releases
sudo apt-get update
sudo apt-get install handbrake-gtk
This link talks about handbrake no longer supporting xbox and ps3 but other say it does
I installed it and created a m4v format ( basically an mp4 with apple compatibility crap) and it worked fine.

Other media streamers I've experimented with are MediaTomb and minidlna. Both are available from the Ubuntu store (for free) and both work well on my Android device. Xbox won't even see MediaTomb, however and minidlna sort of works for music.

For minidlna, you'll want to follow the config instructions at https://help.ubuntu.com/community/MiniDLNA
On extra thing I needed to do was manually create the /var/cache/minidlna directory then grant global permissions to is since it's used by everyone. The commands are
mkdir /var/cache/minidlna
chmod a+rw /var/cache/minidlna
Android

So this is one of those happy finds. I wanted a way to stream my PS3 Media Server to my phone. I found a package called Skifta available from the Google Play and Amazon store. Not only does it let me watch files served from any of the media servers I've listed in the article, it also share my phones media to anyone on my local network. So now I can watch movies on my phone on my Xbox. I use it on both my Kindle and Samsung.

I'm still experimenting with mkv formats on android. The best option so far seems to be creating either an mp4 or avi out of the mkv. A product called avidemux solves the problem. Just select the file type of either avi or mp4 when saving. It takes a while. After that you have video content your android can read.

I'm not happy that avidemux can't create mp4s or avis that xbox can read. I'm sure with a little more digging I could find the proper settings but this will do for now.

Good luck and happy viewing. 

Links

PS3 Media Server - http://www.ps3mediaserver.org/


Friday, January 25, 2013

Writing Update - Prescription for Revenge


If you read this blog often, you know I'm one of the worst at self-editing and not just in a small way either. I have two things working against me, my ADD and my astigmatism. Combine this with normal writer's blindness and you get a powerful typo machine. I'm lucky enough to have friends that are willing to read an unedited manuscript and help correct the inevitable typos and rough patches.

But there's more to editing than just typos. Stephen King once gave a formula for writing: Final = Draft - 10%. My friends have helped me find a few trimming spots so hopefully I'll come in on target. One of the difficult sections of the book comes in chapter 5 and 6 where my 1930's hero is confronted with the race relations of that era. It's a delicate balance. You don't want to beat the reader over the head with how bad things were in 1930s Chicago but you don't want to gloss over them either.

During World War I, many African-Americans migrated from the jobless South to major metropolitan areas such as Chicago. They filled the jobs left empty by the WWI draft. When the servicemen returned, they found blacks in there old jobs. Conflict ensued.

Red Summer, as it was called, occurred in May of 1919 as race riots broke out in a number of cities. Hundreds of home were burned in the Black Belt of Chicago as black fought white for jobs and territory. Eleven years later my story takes place.

I attempted to write about the feelings my World War I veteran protagonist would feel toward persons of color inside a predominantly black neighborhood. My friend editors did not take this section well. I decided to trim back on some of the content. To be honest, it's against my better judgement but I've done it anyway. The concern was almost universal and so I'm left with writing what I feel is right or writing for the enjoyment of others. I suppose on this round I'll write for the enjoyment of others.

On to the next conundrum.


Monday, January 21, 2013

Writer's Blindness


I learned a hard lesson when I began writing with an eye toward publishing. I have one heck of a time finding my own writing errors. You are truly lucky if you're gifted with wonderful self-editing abilities. The rest of us have real issues finding problems in our own work.

Why is smooth copy so important? Because one of your writing goals is to keep your reader in the story or article without thinking of the words you use. In effect, the words should disappear to be replaced with your concept, scene, or action. This is true regardless of whether you're writing fiction, entertainment, or opinion.

For many, a poorly formed sentence or mis-punctuated passage yanks them out of your work completely. They have to work around the error to figure out what you're trying to say. One friend called these 'hard stops.' It completely derails the reading experience.

This isn't unusual. Your brain is a crafty organ. It knows how to get out of work by skipping things it already knows. The slang term for this is "writer's blindness." You know the story so your brain starts skipping words and misses malconstructed sentences over and over again. There are various tricks to overcome this. One is simply changing the screen and font size on your word processor. Your brain sees it as new and you'll pick out a few more errors.

You write as your inner voice dictates. You read a passage and it makes complete sense to you. If the passage has a missing comma or mismatched verb, your readers may have to reread it a few times to understand what you're saying. The way it sounds in your head his not the same way it sounds in theirs if your mind is playing the skip trick.

One way to avoid this is to read your work out loud. While your coworkers or housemates may think it odd to hear you mumbling to yourself while you work, this is a very effective tool for finding awkward passages. Different parts of your brain's language centers activate when you speak. Often this is enough for you to find those bad spots.

Another trick is to find some friends willing to read your work and criticize it. Note, this isn't just any criticism; it's constructive criticism. Someone who glows over your work as the best thing they've ever read is as useless as someone who just says "it sucks" with no reason as to why.

Encourage your friends to sit down with a red pen or a word processor that tracks changes and write things like "awkward", "had to read twice to get it", "what?", and other phrases that help you, the author, find those hard stops. Also have them mark any grammar issues even if they aren't good at it. If something bothers them, it will likely bother someone else.

Lastly, I recommend finding a professional proofreader. If you find a good one, the money you spend will be well worth it to your readers. I'll have more on that subject in a future article.

Hopefully this article gave you a few tricks to make your writing more readable. If you have other tricks of the trade please leave them below in the comments section.