Tuesday, January 12, 2010

fighting with oci8 - apache2 + php5 + Oracle

Connecting to the Oracle database by using apache2 + php5 is simple -- if you already know all the traps along the way.

In order to connect to the Oracle database with my apache2 and php5, I've read several tutorials. Many thanks for them.

I want to talk about my experience -- everything is done correctly, but the phpinfo() still shows no oci8 information.

First, you should take a look at the error log of apache in /var/log.
In my case, my error log shows
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/200 60613+lfs/oci8.so' - libaio.so.1: cannot open shared object file: No such fi le or directory in Unknown on line 0

The log already told me the answer, all I had to do is to install the lobaio.so. I did so and solved the problem.

Another way to discover the problem is to use the ldd command to exam the oci8.so.
linux-gate.so.1 => (0xb7fb3000)
libclntsh.so.11.1 => /opt/oracle/instantclient/libclntsh.so.11.1 (0xb627b000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb610e000)
libnnz11.so => /opt/oracle/instantclient/libnnz11.so (0xb5ec0000)
libdl.so.2 => /lib/i686/cmov/libdl.so.2 (0xb5ebc000)
libm.so.6 => /lib/i686/cmov/libm.so.6 (0xb5e96000)
libpthread.so.0 => /lib/i686/cmov/libpthread.so.0 (0xb5e7d000)
libnsl.so.1 => /lib/i686/cmov/libnsl.so.1 (0xb5e64000)
/lib/ld-linux.so.2 (0xb7fb4000)
libaio.so.1 => not found

It showed the same problem.

Tuesday, January 5, 2010

rrdtool - every data is a rate!

This article is about understanding the rate calculating in the rrdtool.

I'm doing a SA project recently. We get the RTTs(round-trip time) by the ping command and write the RTT to a rrd file, print out the graph, ...

More information about the rrdtool can be found on their website.
http://oss.oetiker.ch/rrdtool/

I first created a rrd file:
rrdtool create F.rrd \
--step 10 \
DS:rtt1:GAUGE:20:0:U \
RRA:MAX:0.5:1:35712

Then, I updated some values to the F.rrd file. A interesting fact is that when I update the value at exact the time step (say 10, 20, 30, etc.), I'll have a accurate value.

# rrdtool update F 1262733290:3
# rrdtool update F 1262733300:4
# rrdtool update F 1262733310:5
# rrdtool update F 1262733320:6

1262733300: 4.0000000000e+00
1262733310: 5.0000000000e+00
1262733320: 6.0000000000e+00

OK, there is a thing called "heartbeat" in the rddtool, it helps the updates that occur at a not-accurate timestamps. For example, if we update a value at time 1262733331, the rrdtool will put the value to 1262733330. It's a nice feature, since there is always some delays in the networking world.

Let's take a look

# rrdtool update F 1262733331:7
# rrdtool update F 1262733340:8

1262733330: 7.0000000000e+00
1262733340: 7.9000000000e+00

As you can see, the value 7 is updated at 1262733331 but is shifted to 126273330 in the rrd file. But what happened with the next update at 1262733340? We update 8 but the rrd file recorded 7.9. Strange, right?

Here is how 7.9 comes out: since rrdtool treats every data as a rate, if there are more than one samples before a time step, rrdtool tries to calculate the average rate of all the samples before the time step (after the previous time step, of course).

previous time step: 1262733330
when we update 7 at 1262733331; 8 at 1262733340.
the calculation is
(7 * (1262733331 - 1262733330) +
8 * (1262733340 - 1262733331) ) / 10 = 7.9

Here is a figure to help understanding:


OK, Let's do the math with another example:

# rrdtool update F 1262733341:54
# rrdtool update F 1262733342:3
# rrdtool update F 1262733347:31
# rrdtool update F 1262733350:3

To find out the average value at 1262733350:
previous time step: 1262733340
(54 * (1262733341 - 1262733340) +
3 * (1262733342 - 1262733341) +
31 * (1262733347 - 1262733342) +
3 * (1262733350 - 1262733347)) / 10 = 22.1

Read the rrd file to verify our answer:
1262733350: 2.2100000000e+01

It's a perfect match. :-)

I hope this article can help someone who has the same question as I did.