Friday, May 27, 2016

Return of the static

While working on some go code recently, I hit a problem which was a bit perplexing:

# command-line-arguments
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
/usr/lib/golang/pkg/tool/linux_amd64/6l: running gcc failed: unsuccessful exit status 0x100

After some consideration, and examination of the go command
go build -v -ldflags '-extldflags '\''-static'\'' -X github.com/xxxx/xxxx.buildVersion=1' -o pkg/xxxx-linux-amd64 main.go
I remembered a change to do with the packaging of static libraries, that is, they are not installed by default on RHEL/CentOS.
A simple
yum install glibc-static
was all that was required

Friday, November 14, 2014

CentOS 6 trackpad configuration

I was going to write a blog about how the synaptics trackpad driver on RHEL6 is a bit old and buggy and that I had successfuly back-ported the updated RHEL7 version. It seems however that RedHat also got round to back-porting the driver and you can just get it with a yum update. No blog entry required after all.

Tuesday, November 11, 2014

PHP Search Speed

I recently had a problem with a PHP command line script I use to sanity check some of our systems.

One particular check compares user accounts across a number of systems. There are ~100,000 user accounts. The script loads data in to memory from various LDAP and SQL interfaces. Once in memory, it iterates through the records and compares them. This process takes a few minutes, mostly spent loading data via LDAP.

I had identified a data problem in one system which uses SQL to get the user data. The SQL in question already joins a few tables and rather than introduce another complex join, I decided to just load the data about the new item into a new array using a separate SQL statement. This added just a few seconds to the script run time. However, once I implemented the record compare, the speed of the script slowed to a halt.

This was unexpected because I regularly process data sets this size and larger in PHP without and problems (once I raise the memory_limit).

This is what I discovered while debugging this problem:
It is well known that the PHP in_array & array_search functions are slow. They perform a linear search on the array resulting in O(n) performance.
Many people have contributed code which can implement a binary search on an array. This in theory reduces the performance to O(log n). My testing shows an improvement in search times but they are still quite slow and not representitive of the perforamce I am use to.
So how was it that I have never had this problem before? A quick inspection of my existing code shows that I always retrieve data by using the key. This results in a hashtable lookup of O(1).
So I changed my code to store my new data in the array key and use isset($array[$key]) and bang! my script is running on time again.

Footnote:

The performance of these functions may not be exactly O(n), O(log n) and O(1) but are close enough to enable comparing the performance of these functions against each other.

Monday, November 10, 2014

Command of the day: ^]

You may have seen it hundreds of times but few know what it means.
Escape character is '^]'.
It is actually quite obvious is you know that the caret ^ is a shorthand notation for 'Control' (or <Ctrl> as would be more familiar to windows users).
So what is it? It is not actually a command but a keystroke for the telnet command. It opens a command prompt from where you can enter a variety of commands.
Possibly the most exciting thing you can do is then press ^Z ( <Ctrl>+z ) and suspend your telnet session, returning you to your local shell. You can then resume later by using your shell job control (ie. 'fg').
Some other useful commands are
  • quit (or press ^C)
  • send brk (which if supported will send a break)
  • speed 115200 (which if supported will switch the serial line speed)
  • close (disconnect the session)
  • open (establish a new session)
  • help (list the available commands)
And there are many more documented in the telnet man page.

In this day and age, any server shell access should be via a secure protocol like ssh. telnet remains however as a handy tool for testing TCP servers and accessing specialised equipment like serial concentrators.

It is also worth noting that telnet is actually a protocol and not just a raw TCP stream. There is a lot of negotiation which is done to ensure that your terminal works correctly. Often this only becomes obvious when your terminal does not work correctly.

Wednesday, November 5, 2014

XBMC 13.2 on CentOS-6

For a while I have been running XBMC 13.0 on CentOS-6. I turns out that there is a known issue in that version which prevents it from playing .m4a files.
The solution is to upgrade to 13.2 which for me means rebuilding a new RPM.
For you, that means downloading the new version from http://www.chrysocome.net/downloads/xbmc-13.2-1.el6.x86_64.rpm
And don't forget to get the deps from http://rpmfusion.org/ and EPEL.

Sunday, November 2, 2014

Command of the day: column

Often I come across a new command which I think Wow! I always wanted to know how to do that.

I decided that I will blog about them and that way I will have a record for next time when I forget how to do it.

So my first command of the day I is one I saw on a Red Hat post. It can show the contents of a file tabulated into easy to read columns.

Example:
cat /etc/passwd | column -s : -t


Now you are probably aware of the <tab> character, often entered as \t or in bash as $'\t'. It will advance the cursor to the next tab stop which is traditionally every 8 characters. Well what if you have a tab delimited file but some data is longer than 8 characters and some it less. Well when you look at it, the output will be all over the place.

Using column you can get all your tab columns to line up like this:
cat data | column -s $'\t' -t
Note: for this to work correctly you must have a value in every column (perhaps a bug?)

Friday, October 31, 2014

PocketWIFI and CentOS-6

Now that I have a laptop I can use on the train I can surf the internet using my Pocket WIFI. This is actually a Vodafone Hauwai E585 with a TPG SIM (Uses the Optus network).
It all works great but I don't get any feedback on the connection status and quality.
I have an app on my phone which does this but I could not find one for Linux so I decided to write one for Linux/Gnome.
Here then is my pocketwifi status applet.
 http://www.chrysocome.net/downloads/pocketwifi-1.0-1.el6.noarch.rpm
  1. Install the RPM
  2. Right click on your gnome panel
  3. Select Add to Panel...
  4. Type in PocketWIFI
  5. Click Add
The applet will automatically detect your route and find the PocketWIFI. It will then query the connection details and download the same status icons which are used on the PocketWIFI screen.


In the future I might add the option to use Gnome icons for  a more consistent look.I might also add support for some other models. If you want your model supported you can drop me an email.