Archive for June, 2007

A Different Kind of Hype

Saturday, June 30th, 2007

No iPhone Bashing Today. But let me enjoy this while it lasts. I’m now at the first page of PinoyTopBlogs. But that’s based from hits. I still know that my blog doesn’t have that much value. Ha ha!

#50

And yes, I know that post frequency went on a low lately. There’s one coming up. Soon.

Bookmarks for 2007.06.27

Wednesday, June 27th, 2007

Quick One-Liner

Tuesday, June 26th, 2007

Bash: Execute a command every X seconds. Forever.
while(true); do your-command && sleep X; done

Vitória Assis

Friday, June 22nd, 2007
Vitória Assis Brasil
Originally uploaded by Patricio Orozco-Contreras.

Purty.

Bookmarks for 2007.06.22

Friday, June 22nd, 2007

Suspend to RAM Issues on Fedora 7

Tuesday, June 19th, 2007

I accidentally switched my laptop to suspend to RAM last night and when I reached home, it safely woke up. I thought an update fixed it but when I tried again this morning, it didn’t work again. By the way, ACPI works better now (the screen actually switches off instead of a black display with the backlight still on).

liquidat posted a workaround. Let me summarize it.

A kernel panic happens when the machine goes to resume. The error is caused by a bug in the Firewire Open Host Controller Interface (fw_ohci). This may be an isolated case for other users so you might need to test it by issuing modprobe -r -v --first-time fw_ohci and suspending then resuming the machine. If the machine was able to resume, then fw_ohci is the cause.

The workaround is to append SUSPEND_MODULES="fw_ohci fw_core" to /etc/pm/config.d/unload_modules (many thanks to Alex Tucker and liquidat).

DZone

Tuesday, June 19th, 2007

Somebody just added one of my entries to DZone. It’s like Digg for developers.

  • DZone is a free link-sharing community for developers
  • anyone can submit new links to the incoming queue
  • members vote on upcoming links to determine what gets promoted
  • everyone can browse, search and comment on links

Bookmarks for 2007.06.19

Tuesday, June 19th, 2007

Load Balancing Two MySQL Servers for PHP Applications

Monday, June 18th, 2007

My “research” on clustering and replication was just timely. I had to find a fix for an overloaded server. I could’ve just rewritten the code but I wanted to try something new first. I found out that a MySQL cluster needs to have at least three servers to get full redundancy. Replication was my only choice because I only have two servers for this application and the queries that are producing the most load are select queries.

MySQL replication works by having a master server where all the inserts, updates and deletes (basically any writing done) and one or more slave servers that polls the master server to replicate the database. You can only issue select queries to the slave server. You can also have multiple master servers but it won’t be covered here. You can follow this article to setup replication.

I’ll be using Round Robin to balance the load since I’ll be load balancing for a separate portion only where the same queries are used. This will equally split the load to each server (…almost). To do this in PHP, I wrote a very simple script that opens a socket. Once a host connects, it tells which database server to connect to and immediately terminates the connection.

#!/usr/bin/php -q
<?php
// Bind and listen
socket_bind($stream, "127.0.0.1",3307);
socket_listen($stream, 100);

// Define DB login credentials in an array
// host|user|passwd
$hosts = array(
0 => array('db1.dbservers.net','someuser','somepass'),
1 => array('db2.dbservers.net','anotheruser','anotherpass'),
/***** if you add another host (just follow the drift) *****/ 
// 2 => array('db3.dbservers.net','yetanotheruser','yetanotherpass') 
);

// Loop forever
while(true)
{
	// Accept anyone
	$client = socket_accept($stream);
	$key = key($hosts);
	$reply = implode($hosts[$key], "|");

	// Move internal pointer to next host
	if(next($hosts) === FALSE)
		reset($hosts);

	// Push response then kill the connection
	socket_write($client, $reply);
	socket_close($client);
}
?>

This script should be called from the command line and run like a daemon. Then we modify how we connect to the database. We connect to the “daemon” and catch the login information.

<?php
// Connect to load balancer daemon
$fp = fsockopen("localhost", 3307);

// Fallback and use some host in case of failure
if(!$fp)
{
	$host = "localhost";
	$user = "someuser";
	$pass = "somepasswd";
}
else
{
	// Get DB login information
	$packet = fgets($fp);
	$account_details = explode("|", $packet);
	$host = $account_details[0];
	$user = $account_details[1];
	$pass = $account_details[2];
}

// Connect
$link = mysql_connect($host,$user,$pass);
if(!$link)
{
	die("Fatal Error: Can't connnect to database\n");
}
mysql_select_db("somedb",$link);
?>

The code above can be improved further to check if a host is still up, give weights on the server depending on its hardware and other bells and whistles.

The beauty of this is you can safely change to another algorithm like Weighted Round Robin or Job Informed and all of the code that has to be changed is in the daemon. You may learn more on other algorithms from the paper by Dennis Haney and Klaus S. Madsen.

I’m looking into venturing to a Job Informed algorithm once the whole application uses load balancing. Queries will have weights then some form of load estimation can be achieved. Query analysis is also a possibility (based on subqueries, query type, constraints ,etc).

Windows Vista, 2007 Office and Windows Live Student and Teacher Bootcamp

Sunday, June 17th, 2007

It’s the start of the new school year! It’s a year full of new lessons, new opportunities, and new challenges ahead. Create professional looking documents, spreadsheets and presentations that will sure impress your teacher and for teachers to inspire their students without spending the whole time trying to figure out how will you make them look professional. Work together without everyone being physically present, with everyone on the loop so that you can pass the best project on-time and with flying colours. Go beyond written notes in a notebook, introduce pictures, voice and video to help you understand the subject matter.

Want to know how all of these and more are possible? Find out on our Windows Vista, 2007 Microsoft Office and Windows Live Student and Faculty Boot Camp.

This event was brought to you by the Philippine Windows Users Group and the Microsoft Juniors.

  • MS101 - Microsoft Windows Vista
  • MS102 - Microsoft Office Word
  • MS103 - Microsoft Office Excel
  • MS104 - Microsoft Office PowerPoint
  • ON101 - Microsoft Office OneNote
  • COL101 - Collaboration: A Quick Run-through of Windows Live

Saturday, July 14, 2007 (9:00 AM - 5:00 PM)
Microsoft Exchange and Office Rooms
Microsoft Philippines
16th Floor 6750 Office Building, Ayala Ave. Makati City
Register here. More details here.

This post isn’t complete without a MSFT joke. The group’s name should’ve been Windows Users’ Group of the Philippines …WUGP - Wag Po [Koya].