And so I've been tasked to create a JMX-based statistics tracker. A key part of my task will be to implement the infrastructure to allow MBeans to be easily created throughout the system, although its first usage will be for monitoring cache statistics and batch performance.
Presently I'm using static objects to store cache hit/put/miss counters. This suffers from the accuracy-vs-performance problem in multi-threaded environments.
And I'm using IBM's ThreadSafeTimeUsed class for measuring batch processing execution time. This uses Timelets, which basically is a new object created each time the timer is started, after which the total time for all the corresponding objects will be calculated for that timer. Since nothing is modified concurrently (even the Timelets container is thread-local), this implementation is pretty much thread-safe. But there is presently no way to retrieve results dynamically during runtime.
JMX will solve the above problems. By sending counters and timer events to an MBean (should this be kept thread-local?), a client on a remote machine can monitor the required statistics dynamically without affecting runtime performance.
Hibernate supports JMX, so maybe I'll start here first. I will also need a client to do the monitoring. MC4J is the option I found on Google, but the Oracle JRockit Mission Control tool is able to monitor MBeans registered on JRockit, so I might be able to use this too.
So here we go.
Sunday, March 29, 2009
Sunday, March 22, 2009
Installing Apache 2.2 / PHP 5 / MySQL 5.1
Step 1: Install MySQL (mysql-5.1.31-win32.msi)
Ensure that you choose to register it as a Windows service (which is a convoluted way of starting the MySQL server automatically on Windows startup), and that you choose to update the PATH environment variable. This will give you the means to test and access MySQL from the command prompt.
Step 2: Install PHP (php-5.2.8-Win32.zip)
Simply unzip the files to a folder of your choice (I placed mine in C:\). There is also a Windows installer for PHP, but I consider it unnecessary.
Now we need to configure PHP to use the MySQL client library, which is located in \php-5.2.8\ext\php_mysqli.dll. This is done in php.ini, which can be copied from one of the templates available in the PHP root folder. The client library is available as a PHP extension, so the first thing we need to do here is to specify where the PHP extensions are to be found. This is done by setting the PHP extensions directive as follows:
Step 3: Install Apache Web Server (apache_2.2.11-win32-x86-openssl-0.9.8i.msi)
After installation, we will need to edit the httpd.conf file at \Apache2.2\conf\httpd.conf. I'll rank the changes by order of importance:
1. Specify the root directory of your web server. I chose to put mine in D:\myserver.
Step 4: Test
How do you know if everything is setup correctly? First thing to do is ensure that your web server is up. Create a file index.html containing the following text:
To test whether PHP is enabled, rename index.html to index.php, and replace the <body> tag with <body><?php Hello PHP World! ?></body>. After reloading the localhost page, you should be able to see the new message 'Hello PHP World!'.
To test whether MySQL is enabled, create a new file testmysql.php containing the following PHP code:
Ensure that you choose to register it as a Windows service (which is a convoluted way of starting the MySQL server automatically on Windows startup), and that you choose to update the PATH environment variable. This will give you the means to test and access MySQL from the command prompt.
Step 2: Install PHP (php-5.2.8-Win32.zip)
Simply unzip the files to a folder of your choice (I placed mine in C:\). There is also a Windows installer for PHP, but I consider it unnecessary.
Now we need to configure PHP to use the MySQL client library, which is located in \php-5.2.8\ext\php_mysqli.dll. This is done in php.ini, which can be copied from one of the templates available in the PHP root folder. The client library is available as a PHP extension, so the first thing we need to do here is to specify where the PHP extensions are to be found. This is done by setting the PHP extensions directive as follows:
; Directory in which the loadable extensions (modules) reside.After which, the extension must be enabled by uncommenting the corresponding line:
extension_dir = C:\php-5.2.8\ext
extension=php_mysqli.dllNotice that there are two extensions available for MySQL: php_mysqli.dll and php_mysql.dll. MySQLi stands for "MySQL, improved", supports an object-oriented programming interface, and supports the Prepared Statements and Multiple Statements API, which is a big deal if you're going to be writing a lot of SQL statements. In any case, MySQLi is meant for newer versions of MySQL, including MySQL 5.1 which we just installed. See http://dev.mysql.com/doc/refman/5.0/en/apis-php.html. Also, the stuff I wrote above about PHP extensions is taken from http://in2.php.net/manual/en/mysqli.installation.php.
Step 3: Install Apache Web Server (apache_2.2.11-win32-x86-openssl-0.9.8i.msi)
After installation, we will need to edit the httpd.conf file at \Apache2.2\conf\httpd.conf. I'll rank the changes by order of importance:
1. Specify the root directory of your web server. I chose to put mine in D:\myserver.
#2. Enable the PHP module, and specify where php.ini is to be found:
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "D:\localserver"
....
#
# This should be changed to whatever you set DocumentRoot to.
#
<directory>
....
</directory>
# PHP 53. Specify that your website's index can be a PHP file. This is the file that gets loaded when you type in your base url in the browser (eg www.google.com)
LoadModule php5_module "C:/php-5.2.8/php5apache2_2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php-5.2.8"
#Be sure to restart the web server after making any changes to httpd.conf or php.ini.
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<ifmodule>
DirectoryIndex index.html index.php
</ifmodule>
Step 4: Test
How do you know if everything is setup correctly? First thing to do is ensure that your web server is up. Create a file index.html containing the following text:
<html>And place it in your webserver's root folder (ie D:\myserver\index.html). Now point your web browser to http://localhost/. You will see a page saying 'Hello World!' with the corresponding title.
<header><title<Hello Title Bar!</title></header>
<body>Hello World!</body>
</html>
To test whether PHP is enabled, rename index.html to index.php, and replace the <body> tag with <body><?php Hello PHP World! ?></body>. After reloading the localhost page, you should be able to see the new message 'Hello PHP World!'.
To test whether MySQL is enabled, create a new file testmysql.php containing the following PHP code:
<?phpPlace this file in the same directory as index.php, and open it using the url http://localhost/testmysql.php.
$connection = @mysqli_connect('localhost', 'yourusername', 'yourpassword');
if (!$connection) {
echo 'Failed to connect to your MySQL database server.
The following error message was reported: '.mysqli_connect_error();
} else {
echo 'MySQL Database connection successful.';
}
?>
Learning Drupal
In addition to my full-time job (at which I feel I'm pretty proficient), I'm helping to maintain and improve a sports organization's website in my free time (at which I feel like a total amateur).
I won't reveal the site name, as it still looks embarrassingly crummy. I took over the site about 4 years ago. Then, it was a 100% HTML-based site, with a couple of static pages and i-frames for layout. I turned it into another crummy HTML-based site with i-frames, and then, after reading that i-frames constitute bad design, I redesigned the site and used PHP for navigation and a few basic blocks.
The site seemed pretty complete then. It was neat and navigable and the CSS made it look pretty pleasant. But I wanted to add an Ajax interface, incorporate a database, and turn it into a community portal for the organization's members, in the hope that this will be my springboard to a home-based web development career. So I tried to write an Ajax-based CMS by hand, and got stuck at the user interface. It didn't help too that I could spare only a couple of hours per month at that time, being overly preoccupied by my intriguing classes a
Then I entered the wonderful world of ready-made CMSs. I had a few options: Mambo, Joomla, Xoops, Drupal. I chose Drupal, as it seemed the most "open-source" of the four. Granted, Joomla and co. have much nicer pre-defined modules and themes, but one of my motivations here is to master PHP and become an open-source contributor. The positive reviews I found about Drupal's modular layout and "hook"-based mechanism helped guide my decision.
So I installed and configured Drupal for the website, dumped in all kinds of modules which I found interesting, tried to create my own custom theme, and made a right old mess of it all. Drupal is truly not for the newbie-hearted, and I ought to have practiced and gotten it right on my own development server first before publishing the site.
So here I am, setting up a development server on my Windows machine. Here's the plan:
1. Install Apache-PHP-MySQL-Drupal, and create a clean instance of a Drupal website
2. Import the database dump from the production server, and replicate the messed-up production environment on my local server.
3. Read Pro Drupal Development 2nd Edition, and learn what I need to learn about Drupal while practising on the clean instance.
4. Build up the clean instance with the desired features, and an optimal configuration, and import the client data here.
5. Export the clean instance into the production environment.
I won't reveal the site name, as it still looks embarrassingly crummy. I took over the site about 4 years ago. Then, it was a 100% HTML-based site, with a couple of static pages and i-frames for layout. I turned it into another crummy HTML-based site with i-frames, and then, after reading that i-frames constitute bad design, I redesigned the site and used PHP for navigation and a few basic blocks.
The site seemed pretty complete then. It was neat and navigable and the CSS made it look pretty pleasant. But I wanted to add an Ajax interface, incorporate a database, and turn it into a community portal for the organization's members, in the hope that this will be my springboard to a home-based web development career. So I tried to write an Ajax-based CMS by hand, and got stuck at the user interface. It didn't help too that I could spare only a couple of hours per month at that time, being overly preoccupied by my intriguing classes a
Then I entered the wonderful world of ready-made CMSs. I had a few options: Mambo, Joomla, Xoops, Drupal. I chose Drupal, as it seemed the most "open-source" of the four. Granted, Joomla and co. have much nicer pre-defined modules and themes, but one of my motivations here is to master PHP and become an open-source contributor. The positive reviews I found about Drupal's modular layout and "hook"-based mechanism helped guide my decision.
So I installed and configured Drupal for the website, dumped in all kinds of modules which I found interesting, tried to create my own custom theme, and made a right old mess of it all. Drupal is truly not for the newbie-hearted, and I ought to have practiced and gotten it right on my own development server first before publishing the site.
So here I am, setting up a development server on my Windows machine. Here's the plan:
1. Install Apache-PHP-MySQL-Drupal, and create a clean instance of a Drupal website
2. Import the database dump from the production server, and replicate the messed-up production environment on my local server.
3. Read Pro Drupal Development 2nd Edition, and learn what I need to learn about Drupal while practising on the clean instance.
4. Build up the clean instance with the desired features, and an optimal configuration, and import the client data here.
5. Export the clean instance into the production environment.
Sunday, March 8, 2009
Hello World!
First post of this e-journal/weblog, which is also my first blog dedicated to my technical pursuits (the earlier blogs were about football and dating, ramblings about the meaning of life, etc).
I am Alvin, born and based in Singapore but presently in Mumbai for my 2nd stint with the Flexcube Retail development group at Goregaon. I graduated from NUS School of Computing in May 2007, and since then have been working for Oracle Financial Software Services (previously known as i-flex solutions).
At NUS, I majored in Computer Science, but feel that I'd wasted my four years there. Everything I learnt at NUS, I could have learnt better by reading Wikipedia and technical articles online. Given that I'm the geeky-loner type, my time at NUS was overall a pretty sad experience, although I did meet the lovely woman who is now my wife. I also gained a strong base in core Java programming, which helps in my present job.
But knowing core Java is not enough. Upon graduation, I still did not know what is a Java Bean. I had no inkling of the importance of messaging in software systems. I had no idea what virtualization means. I'd never encountered the concept of stored procedures. I thought that service-oriented architecture had something to do with Burger King's restaurant layout.
Now, after spending almost 2 years in the field, I know (slightly) better. This blog shall attempt to record the following:
I am Alvin, born and based in Singapore but presently in Mumbai for my 2nd stint with the Flexcube Retail development group at Goregaon. I graduated from NUS School of Computing in May 2007, and since then have been working for Oracle Financial Software Services (previously known as i-flex solutions).
At NUS, I majored in Computer Science, but feel that I'd wasted my four years there. Everything I learnt at NUS, I could have learnt better by reading Wikipedia and technical articles online. Given that I'm the geeky-loner type, my time at NUS was overall a pretty sad experience, although I did meet the lovely woman who is now my wife. I also gained a strong base in core Java programming, which helps in my present job.
But knowing core Java is not enough. Upon graduation, I still did not know what is a Java Bean. I had no inkling of the importance of messaging in software systems. I had no idea what virtualization means. I'd never encountered the concept of stored procedures. I thought that service-oriented architecture had something to do with Burger King's restaurant layout.
Now, after spending almost 2 years in the field, I know (slightly) better. This blog shall attempt to record the following:
- all the things I've learnt and am still learning with regard to technology
- my experiences and challenges with regard to my day job
- my attempt to become proficient at web programming
- my thoughts on Linux and open-source technology
Subscribe to:
Posts (Atom)