Feb 04

A few months ago, I had a very sudden and strange thing happen to the QuickGPS app on my Windows Mobile HTC Touch Cruise smartphone.  My GPS signal would take forever to get a signal and when I opened QuickGPS and clicked Download now I got the error "Connection failed. Please try again later".  Needless to say, later didn't help. It also said:

Download time: Not yet downloaded
Valid time: Expired

It happened if I was connected over 3G, GPRS, or through USB/ActiveSync. All other data networking is fine.  But nothing worked.   After many hours of googling I found this page. Basically, for some reason one or more of the phone's registry settings are busted and need to be fixed (at least it was in my case).  I grabbed an application that let you edit the registry on the phone and then verified these registry settings - and my problem was fixed!

[HKEY_LOCAL_MACHINE\Software\HTC\QuickGPS]
"RemindTime"="02151010034724"
"Bias"=dword:fffffed4
"ExpiredTime"=dword:00002760
"folder"="\Windows\"
"region"="US"
"INIDate"="20060531"
"remind"=dword:00000001
"actSync"=dword:00000001
"auto"=dword:00000000
"NotifyID"=dword:00001960
"INIFile"=""
"path"=""
"EEFile"="xtra.bin"
"curRegion"=dword:00000000
"curIP"=dword:00000000
"pwd"="1"
"authname"="1"

If editing the registry doesn't sound like your kind of thing, someone in the forum of the above link has a cab file that makes the changes for you.

Feb 03

The Usual Disclaimer
Please beware that even if these instructions work, that they may break your setup.  While these worked fine for me, you should take extreme care applying them to your situation.  Follow these instructions at your own risk. They work fine for me on a CentOS 4.6 box with cPanel 11.23.4-R26138 and WHM 11.23.2.

First off, Phusion Passenger only works with Apache 2.x so if your server doesn't have that thats the next thing you'll have to do.  T o upgrade Apache, go to your main control panel at https://server.ip.address:2087/ and click the "Apache Update" link on the left.  If given the option, I highly recommend that you choose Apache 2.2 instead of 2.0.

Next, download Passenger. Assuming you already have Ruby and RubyGems installed on your server, simply run (as root) gem install passenger. This will pull the passenger library and code down to the server and place it with your other RubyGems.  It's important to know that this does not install Passenger into Apache, so obviously its non-operational.  If you don't have Ruby and RubyGems, you're way too far down the line with reading this article and need to get up to speed with actually getting those on to your box.  Google can help with that!

At this point it's probably useful to have the Passenger User Guide up on screen, just for reference.

Third, you need to compile and install the Passenger module within Apache. This sounds worse than it is, but before you do it, it is important to set a couple of environment variables to make it work properly.  In your SSH console type thrse two commands into it:

export APXS2=/usr/local/apache/bin/apxs
export APR_CONFIG=/usr/local/apache/bin/apr-1-config

Next, run:

passenger-install-apache2-module

It might take a few minutes, but if everything goes well you'll eventually end up with Passenger telling you to add a few lines to your Apache configuration file (the code you get may differ slightly):

LoadModule passenger_module /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/lib/ruby/gems/1.8/gems/passenger-2.0.2
PassengerRuby /usr/local/bin/ruby

However, despite what it tells you, do not put it in the httpd.conf file - cPanel can rewrite that file and your changes can be lost breaking your passenger configuration and virtual site.  Instead, add it to /usr/local/apache/conf/includes/pre_virtualhost_global.conf - this file might not exist until you make it, but that's okay.

Lastly restart Apache and if you didnt get any critial errors, you should be in business.  I have had issue on other servers where the Rails app failed to load because the RubyGems version was too old, so keep your eye on the error_log file if Apache starts but it still doesn't work.  Also refer to the Passenger User Guide for further configuration and usage information.

Jan 22

Recently at the office we had a brown-out with devastating consequences.  All our servers are managed by UPSes and on this particular occasion, at the precise moment of this brownout the UPS failed and server lost power abruptly.  This caused some error in Directory Services, becasue after the boot the Windows Server 2003 (and primary domain controller) showed a message during bootup (but after logon) saying "The Active Directory is rebuilding indices", just before network connection preparations. It hadn't done this before.

After several hours waiting for this to go away (the server seemed responsive during the process so we left it) nothing changed.  We forcibly reboot the machine and it booted into Safe Mode automatically.

After several reboots and a scheduled CHKDSK /f on bootup, nothing changed, so we booted into Directory Services Repare mode to investigate further.  Now, looking through the event log showed that even more things were going wrong including the computer name being missing the domain being all messed up and an array of other issues, the most worring being several Event Id's 1168 and 1003.

After a bit of googling I found this page, and based on my own knowledge condensed and modified the solution to work in my case:

  • First, boot the machine into Directory Services Repair Mode
  • Next, open a command window.
  • Then, type the command: cd %SystemRoot%\Ntds
  • Execute the command: Esentutl.exe /p Ntds.dit for me this took 8.3 seconds to execute.

Basically, the esentutl.exe is a utility used to perform various administrative actions on any databases using  Microsoft Proprietary Database format.  The Directory Services Database uses this format.  The '/p' argument tells the utility to perform a "repair" on the second argument, which obviously is the database file.

Warning: The Ntds.dit file is the heart and soul of Active Directory on your domain.  Take extreme care with this file because if you don't have an adequate backup of the system state on the domain controller, you may irrecoverably corrupt your domain.  This would be bad.

In my case, everything went smoothly, and the domain was back up after a reboot back into "normal" mode.  Obviously, we changed the UPS with a working one.  Who says network admins never get a happy ending?

Dec 20

My workstation at work is a great little computer. It's running Windows 7 and its very reliable and does what I need it to do. However, periodically, usually during periods of large quanities of network traffic, it will freeze. No BSOD, no warning, just frozen.

After some googling, it seems that the on-board Atheros L1 Gigabit Ethernet adpater on the ASUS motherboard has a known issue with Windows Vista, and apparently Windows 7 as well:

Install a new driver The problem may be especially prominent with the Atheros L1 Gigabit Ethernet 10/100/1000Base-T Controller used on ASUS p5k motherboards. This driver (FTP Link), intended for Windows Vista, has been reported to solve this issue under Windows 7 in a variety of cases.

I downloaded the driver from here, and installed it on top of the generic Windows driver for the NIC and not a single freeze or lock-up since.

If you have an ASUS P5K series motherboard, I highly recommend that you upgrade this driver (even if you're not having these problems as the performance seems better on these drivers).

Dec 04

Unless you actually like the plain, old, boring Notepad (which basically hasn't changed since 1985) - then you're probably already aware of a great replacement for it, called Notepad++.  To put it short, it's an amazing little text editor with a feature as long as my arm, including syntax highlighting for virtually every scripting language you can think of.  It also has integration into Windows Explorer, so it's easy to right-click and edit files which are not associated directly to Notepad++.

For years, it has never let me down, and while it still continues to serve faithfully, this week the following message started to appear every time I opened it on my 64bit Windows 7 workstation:

Configurator
Load langs.xml failed!
OK

That obviously also means that I lost my syntax highlighting.  I could get it back, but I had to manually select the type of file I was editing.  Normally this is automatic.

Somehow, the langs.xml had errors in it. Perhaps while exploring various Notepad++ options I accidentally made unintended changes to it.  I don't know, but when I went to the Notepad++ installation directory, the langs.xml file had a file size of 0 bytes.

So while in the installation folder for Notepad++ I renamed langs.xml to langs.xml.bad. Then, in that same folder, I copied langs.model.xml, and renamed the copy to langs.xml.

This fixed this problem for me, hopefully it will work for you as well. You may want to then compare the langs.xml to langs.xml.bad and see if there is anything legitimate that you want back - but in my case It was fairly obvious that the langs.xml file was pretty useless in it's 0 bytes state.

Oct 12

While using a Windows VM on my MacBook today, I needed some files off a Windows install disk. I put the disk is with no problems, did what I needed to do, and then tried to eject it. You can imagine my suprise when I could hear the drive (making its really ugly crunching sound) and then - no disk.

So I pressed eject again. Nothing.

And again. Nothing. hrmm. This wasn't looking good.

So I went back to OSX, and the disk wasn't being detected by OSX - despite working fine the VM. I pressed the eject button. Nothing. I logged off (thinking some app had locked the superdrive). Pressed eject. Nothing. Rebooted, holding the mouse button down(I'd heard this does an eject if done on boot) - still nothing.

I was worried.

In a last ditch attempt, I found the terminal command 'drutil tray eject' which made the right sounds, but didn't eject the disk. hrmm, getting closer. I thought to myself "I wonder if it's stuck on something?" and then (and I have to admit that I felt like i was molesting my Mac) - stuck the tip of a plastic cable tie into the slot poked around a bit (a little, just enough to feel some resistance inside) and tried 'drutil tray eject' again in the terminal window.

The disk ejected, like a good little MacBook.

Oct 04

I was fortunate enough recently to get a license of Windows 7 x64 Home Premium which I promptly installed on my (non-pro) 15" MacBook.

The install through the OSX Boot Camp wizard went really smoothly and wireless and most other drivers worked out of the box. However, on my early 2008 MacBook, the audio driver did not work (instead only red light constantly came out of the audio jack). Obviously, the driver provided by Boot Camp is not the right one. From my experiences using XP on my Mac, I remembered that the audio card is made by Realtek. After lots of googling, I downloaded the driver directly from Realtek and it worked. Here is the download link. The one I downloaded is Vista Driver (32/64 bits) Driver Version R2.14. Extract the files and run the setup.exe.

BTW, if you are looking for some older versions, you can use this ftp site.
ftp://202.65.194.211/pc/audio/. This is a mirror site used by Realtek. Note that the download speed is kinda slow, so be patient.

Oct 03

Recently, I've been dealing with databases at work which have millions if not BILLIONS of records.  So as you can imagine, having Postgres running smoothly and as quickly as possible, is of utmost importance.  So, as a guide, and compiled from a number of sources. Obviously faster, better, bigger hardware will make the database faster, but there are often other steps you can take to get PostgreSQL working a bit smarter, and a bit harder. The first place to start with Postgres optimization is the Postgres configuration. The list below provides a guide (use at your own discretion) of some of the primary settings relating to resource use. Even small tweaks can have a big impact on server performance.

max_connections. This option sets the maximum number of database back end processes to have at any one time. Use this feature to ensure that you do not launch so many back ends that you begin swapping to disk and kill the performance of all the children. Depending on your application it may be better to deny the connection entirely rather than degrade the performance of all of the other children.

shared_buffers. Editing this option is the simplest way to improve the performance of your database server. The default is pretty low for most modern hardware. Shared buffers defines a block of memory that PostgreSQL will use to hold requests that are awaiting attention from the kernel buffer and CPU. The default value is quite low for any real world workload and need to be beefed up. However, unlike databases like Oracle, more is not always better. There is a threshold above which increasing this value can hurt performance.

PLEASE NOTE. PostgreSQL counts a lot on the OS to cache data files and hence does not bother with duplicating its file caching effort. The shared buffers parameter assumes that OS is going to cache a lot of files and hence it is generally very low compared with system RAM. Even for a dataset in excess of 20GB, a setting of 128MB may be too much, if you have only 1GB RAM and an aggressive-at-caching OS like Linux.

Note that on Windows (and on PostgreSQL versions before 8.1), large values for shared_buffers aren't as effective, and you may find better results keeping it relatively low (at most around 50,000, possibly less) and using the OS cache more instead.

It's likely you will have to increase the amount of memory your operating system allows you to allocate at once to set the value for shared_buffers this high. If you set it above what's supported, you'll get a message like this:

IpcMemoryCreate: shmget(key=5432001, size=415776768, 03600) failed: Invalid argument 
 
This error usually means that PostgreSQL's request for a shared memory
segment exceeded your kernel's SHMMAX parameter. You can either
reduce the request size or reconfigure the kernel with larger SHMMAX.
To reduce the request size (currently 415776768 bytes), reduce
PostgreSQL's shared_buffers parameter (currently 50000) and/or
its max_connections parameter (currently 12).

effective_cache_size. This value tells PostgreSQL's optimizer how much memory PostgreSQL has available for caching data and helps in determing whether or not it use an index or not. The larger the value increases the likely hood of using an index. effective_cache_size should be set to an estimate of how much memory is available for disk caching by the operating system, after taking into account what's used by the OS itself, dedicated PostgreSQL memory, and other applications. This is a guideline for how memory you expect to be available in the OS buffer cache, not an allocation! This value is used only by the PostgreSQL query planner to figure out whether plans it's considering would be expected to fit in RAM or not. If it's set too low, indexes may not be used for executing queries the way you'd expect.

Setting effective_cache_size to 1/2 of total memory would be a normal conservative setting, and 3/4 of memory is a more aggressive but still reasonable amount. You might find a better estimate by looking at your operating system's statistics. On UNIX-like systems, add the free+cached numbers from free or top to get an estimate. On Windows see the "System Cache" size in the Windows Task Manager's Performance tab. Changing this setting does not require restarting the database (HUP is enough). .

work_mem. This option is used to control the amount of memory using in sort operations and hash tables. While you may need to increase the amount of memory if you do a ton of sorting in your application, care needs to be taken. This isn't a system wide parameter, but a per operation one. So if a complex query has several sort operations in it it will use multiple work_mem units of memory. Not to mention that multiple backends could be doing this at once. This query can often lead your database server to swap if the value is too large. This option was previously called sort_mem in older versions of PostgreSQL.

max_fsm_pages. This option helps to control the free space map. When something is deleted from a table it isn't removed from the disk immediately, it is simply marked as "free" in the free space map. The space can then be reused for any new INSERTs that you do on the table. If your setup has a high rate of DELETEs and INSERTs it may be necessary increase this value to avoid table bloat.  Sets the maximum number of disk pages for which free space will be tracked in the shared free-space map. Properly adjust upward to make vacuum runs faster and eliminate/reduce the need to “vacuum full” or “reindex”. Should be slightly more than the total number of data pages which will be touched by updates and deletes between vacuums. Requires little memory (6 bytes per slot), so be generous adjusting its size. When running vacuum with “verbose” option, DB engine advises you about the proper size.

fsync. This option determines if all your WAL pages are fsync()'ed to disk before a transactions is committed. Having this on is safer, but can reduce write performance. If fsync is not enabled there is the chance of unrecoverable data corruption. Turn this off at your own risk.

commit_delay = and commit_siblings. These options are used in concert to help improve performance by writing out multiple transactions that are committing at once. If there are commit_siblings number of backends active at the instant your transaction is committing then the server waiting commit_delay microseconds to try and commit multiple transactions at once.

random_page_cost. Sets estimated cost of non-sequentially fetching. Lower it to influence the optimizer to perform index scans over table scans.

Note that many of these options consume shared memory and it will probably be necessary to increase the amount of shared memory allowed on your system to get the most out of these options.

If you are after a more comprehensive list of Postgres' Tuning and Performance, the PostgreSQL documentation has a great wiki on the subject.

The other place that often gets overlooked for performance enhancement, is the actual database queries themselves.  I must admit ignorance myself to the Postgres inclusing of the 'EXPLAIN ANALYSE' keywords preceding any SQL statement which returns a very comprehensive trace of the query through the database entry, including specific timings, index use etc, which can be a big eye opener to tables, sorts or indexes which maybe being used incorrectly, or just being slow.  Here is an example of explain analyse on a SQL statement on a very large database:

EXPLAIN ANALYSE SELECT items.etag, subscriptions.subscription_data
FROM items, subscriptions WHERE items.item_id = subscriptions.item_id;

returns the entire query plan, like:

"Hash Join  (cost=1.29..22.38 rows=50 width=64) (actual time=0.055..0.084 rows=21 loops=1)"
"  Hash Cond: (subscriptions.item_id = items.item_id)"
"  ->  Seq Scan on subscriptions  (cost=0.00..17.70 rows=770 width=36) (actual time=0.010..0.012 rows=21 loops=1)"
"  ->  Hash  (cost=1.13..1.13 rows=13 width=36) (actual time=0.027..0.027 rows=13 loops=1)"
"        ->  Seq Scan on items  (cost=0.00..1.13 rows=13 width=36) (actual time=0.008..0.014 rows=13 loops=1)"
"Total runtime: 0.154 ms"
Jun 18

As a long-time Windows user and programmer, I cannot state enough just how great Mac OSX is as a development environment.  It comes with so many tools already installed as standard ready to go (or at the very least on the OSX install disk).

Like I said, mac osx comes with a subversion client out of the box. At least Leopard does. If you do not believe me, try the following command and watch the output:

svn, version 1.4.4 (r25188)
compiled May 31 2008, 03:45:57

Copyright (C) 2000-2006 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles 'http' scheme
- handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
- handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
- handles 'file' scheme

However, as you can see, the default Subversion client (type: svn --version in a terminal window) is quite old.  The biggest problem to me is that I use Versions and that stops NetBeans IDE and the command-line client no longer work.  But no fear! It turns out it is very easy to update it.

  1. Head over to http://svnbinaries.open.collab.net/servlets/ProjectDocumentList?folderID=164&expandFolder=164&folderID=0 and grab the correct version of subversion for you, download and install it.  So long as the new version is higher than the old, you can just install and it will copy over the old version.
  2. Make sure that the new binaries are on the path before the original subversion libraries.  To do this, issue the following command in a terminal: export PATH=/opt/subversion/bin:$PATH

If you type: svn --version into a terminal window again you will now see the version you installed.

svn, version 1.5.4 (r33841)
   compiled Oct 27 2008, 11:19:10

Copyright (C) 2000-2008 CollabNet.
Subversion is open source software, see http://subversion.tigris.org/
This product includes software developed by CollabNet (http://www.Collab.Net/).

The following repository access (RA) modules are available:

* ra_neon : Module for accessing a repository via WebDAV protocol using Neon.
  - handles 'http' scheme
  - handles 'https' scheme
* ra_svn : Module for accessing a repository using the svn network protocol.
  - with Cyrus SASL authentication
  - handles 'svn' scheme
* ra_local : Module for accessing a repository on local disk.
  - handles 'file' scheme
* ra_serf : Module for accessing a repository via WebDAV protocol using serf.
  - handles 'http' scheme
  - handles 'https' scheme

Hope this post helps you use the new and improved subversion.

Apr 09

Recently I had do to a lots of PostgreSQL database administration as I needed to move several databases onto  a production server.  PostgreSQL is one of the most robust, open source database servers available, and for my money, faster and generally better than MySQL. Like MySQL database server, it provides utilities for creating a backup.

Backup database using pg_dump command. pg_dump is a utility for backing up a PostgreSQL database. It dumps only one database at a time.

$ pg_dump table | gzip -c > table.dump.tar.gz

Another option is use to pg_dumpall command. As a name suggest it dumps (backs up) each database, and preserves cluster-wide data such as users and groups. You can use it as follows:

$ pg_dumpall | gzip -c > all.dump.tar.gz