Sunday, March 25, 2007

Sometimes print is bad

I wrote a simple Ruby script that, given a connection request on a particular port, opens a connection to a remote host on a particular port and forwards all packets from one to the other, a very simple packet forwarder. For debugging purposes, I was printing some text to standard out for each packet received / forwarded. I set up a simple performance test running the forwarder on my local system and generating packets using /dev/zero...something like this:

ruby forwarder.rb 20000 10000 localhost
nc -l -p 10000 -c "cat /dev/zero"
nc localhost 20000 > moo

After running this test for 15 seconds, the output file "moo" reached a size of 48MB on my laptop, indicating a throughput of over 3 MBps. Although this was sufficient for my purposes, it was much lower than I expected given that transfer should only be limited by the speed of my laptop harddrive in writing the output file.

By simply removing all "puts" calls for output, the performance increased dramatically. With the same 15 second run, the output file "moo" reached a size of 350MB on my laptop, indicating a throughput of over 23 MBps!

I suppose that when writing an application that handles a large amount of data, all debugging should obviously be turned off. However, it wasnt obvious to me that it could have such a large impact on performance. Hopefully this will help me not make the same mistake in the future.

Thursday, March 15, 2007

Ruby Trix

I've been having a number of problems in Ruby of late with error handling in Threads. In particular, any time I encounter a problem in a thread, I was given no indication that something went wrong.  It turns out that by default, an unhandled exception simply kills the current thread and you don't even hear about it unless you issue a "join" on the thread that raised the exception.  I suppose proper coding practice would be to handle my exceptions appropriately, but for debugging, it is nice to know when something has gone wrong.  The simple snippet of code:

Thread.abort_on_exception = true

takes care of this problem.  With this modification, any unhandled exception kills all running threads and yields readable error information.

Monday, November 13, 2006

Don't Fall In

Shocking proof that women, and even some men are afraid to admit that they go number 2...

http://news.bbc.co.uk/2/hi/health/6128738.stm

I wonder what they did in the olden days before bathroom stalls offering doors and some semblance of privacy existed?  Not only that, but what does this say about other things these people might be hiding from themselves and others?  Denail and self-consciousness knows no bounds.

Tuesday, November 07, 2006

Dont let the tabs control you!

The biggest shortcoming of the epiphany web browser in my opinion is the inability to dynamically modify the size of tabs so once you have too many open, you cant see them all at once. Fortunately, epiphany has an amazingly simple interface to create browser extensions to modify its behavior. Save the python code below in the .gnome2/epiphany/extensions folder as tabs-left.py


#!/usr/bin/env python

"""A simple extension to move the browser tabs to the left."""

import epiphany

def attach_window(window):
notebook = window.get_notebook()
notebook.set_tab_pos("GTK_POS_LEFT")


def detach_window(window):
notebook = window.get_notebook()
notebook.set_tab_pos("GTK_POS_TOP")


And save the code below in the same folder in the file tabs-left.ephy-extension. Restart Epiphany and you will have a new extension appear under tools. Once selected, browser tabs will appear along the left side of the browser window rather than the top, allowing for a much larger number of tabs to be visible at once at the expense of some screen real estate. A fair tradeoff in my opinion.


[Epiphany Extension]
Name=Tabs to Left
Description=Moves the browser tabs to the left side of the window. Also, tabs can be closed by middleclicking.

[Loader]
Type=python
Module=tabs-left

Tuesday, October 31, 2006

The Golden Path

Just found out today after a few hours of banging my head against a wall that in every version of Windows, you cant have a file path longer than 260 characters.  Thanks to Microsoft's neverending support for the original Win32 API, this bug is not really fixable.  More info can be found at:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/naming_a_file.asp

Maximum Path Length

In the Windows API, the maximum length for a path is MAX_PATH, which is defined as 260 characters. A path is structured in the following order: drive letter, colon, backslash, components separated by backslashes, and a null-terminating character, for example, the maximum path on the D drive is D:\<256 chars>NUL.

The Unicode versions of several functions permit a maximum path length of approximately 32,000 characters composed of components up to 255 characters in length. To specify that kind of path, use the "\\?\" prefix.

Of course when you are running a ruby script inside of cygwin inside of windows, getting at those Unicode versioned functions might not be so easy :(

Thursday, September 07, 2006

confusion

As the title says, this post is a big heaping pile of nonsense that most people would be better off just skipping completely.

There seems to be an endless supply of interpersonal interactions in life that I don't have a clue how to handle.  How did I ever make it to this point without mastering, or at least familiarizing myself with these skills?

Case in point...names...I cant remember them for the life of me.  I know that this situation could EASILY be remedied by making a point of saying the person's name every time I talk to them, even if it is a bit odd at first.  Perhaps some sort of word association would also help.  Rather than fix the problem I stick to my regular routine of never saying names in fear that I might forget one someday.

There are countless other examples, but I don't care to enumerate them at this time...

Tuesday, September 05, 2006

ernesto strikes

With much needed rain and a cool breeze, Ernesto moved through on Friday. Left behind was a path of leaf destruction and a power outage in my neighborhood...what a surprise! Fortunately, as I mentioned earlier, I purchased an oil lamp for just such an occasion. Since I had never used one of these archaic devices, it took me a while to get it going (apparently, you have to let the oil soak into the cloth wick thingy which takes forever). Burning cloth also sets off fire alarms pretty easily, so if you have a hypersensitive one like I do, might want to rip it out of the socket and throw it at something before you proceed. Anyways, I survived my fourth night without power this summer with neither bumps nor bruises...and managed to read a few chapters of my latest book in the process :)