5th October 2006

Update 1.0

Yeah !

It is finally 1.0 ! So what’s new ? well, because loading this page with the counter appeared so slow to me, both from my office and my home, I was thinking : “bloody free.fr, they are damn slow with sql requests !”.

So I thought, perhaps I should optimize the amount of requests. It was pretty bad : I needed 3+n’ requests, with n’~=n/2 and n being the amount of rows in that table. The 3 first one are necessary, to check the user’s password, insert a hit, and collect data from the table for stats display. The n’ requests are for all of those hits where the hostname was not of this format : “.xx”, or where there wasn’t any hostname but an IP address. I would then consult the ip2country table, for each of them. I rewrote that part, to store all those IP addresses in a table, and at the end, make only one requests. Sounds easy, it wasn’t that much. But it made me improve the readability of my code in the same time.
– optimized amount of requests;
– improved readability;

Then, I tried it again. Damn, it is still very slow ! what the heck ??? Let’s put a few timers around the different parts of the code, to check how much time my requests are taking.
– created log.txt for time control;

OOPS, big surprise Einstein : it is not the requests (<1s), but the processing that takes long : 20s ! Let’s look closely at the code. When checking in my home-made array of country codes, it has to go through it till it finds the good one. Too slow, lets make it quicker. I can just call the result of $country[“.xx”] and if the result isn’t a country, then it’s not in the list, meaning, the end of the hostname isn’t a 2 letter code (ie : “.com”), or I only have an IP, or it is a 2 letter code but I don’t know this one.
– improved the call to the “.xx” country code array;

What about now ? Damn, still 20 seconds. Well, at least, the code looks nicer now. Checking the code carefully to guess what makes it that slow, I came upon that line :
$no_ip=gethostbyname($row[‘hitHost’]);
That’s it of courrrrse ! (with a French accent)
So what was it ? the story is that I was storing only the hostname, thinking it would be indeed redundant to store also the IP address. But then, since I needed it, I converted the hostname into an IP address with that line, whenever the country code array wouldn’t help. Probably one out of two cases, probably more. Good idea at the time, if only doing it wasn’t painfully slowing down everything … I decided then I would also store the IP addresses, changing the table structure, the hit insertion script, and the processing of data. I also had to write a small script to fill all the previous inserted hits with the correct IP addresses.
– optimized the process of information;

Now, what does the log say ? 2s altogether (previously >20s), muuuuuuch better ! and those 2 seconds are only coming from the request to the ip2country table. I can’t do much about that, and sometimes it takes no time at all, depending probably on the charge upon the server. Well, that’s what I call progress !

And what about the user pages ? sorry guys, I didn’t have time to touch them much. Neither did I touch the “programmation” page with the doc and the zip file so far since version 0.7. But I made available the user pages though, so that you can try it if you like. The same link can be found on the left hand side of this page, just under Home, you’ll find Khrys WebCounter. If you feel lost with it, if you need any help, or simply want to give your opinion/advice, please leave a comment on this post.

This entry was posted on Thursday, October 5th, 2006 at 2:17 and is filed under in English please !, Khrys WebCounter, programmation. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.

  • Search

  • Archives

  • Map plugin activated