{"id":86,"date":"2006-10-05T02:17:09","date_gmt":"2006-10-04T23:17:09","guid":{"rendered":"http:\/\/khrys.is-a-geek.org\/wordpress\/?p=86"},"modified":"2006-10-05T02:29:34","modified_gmt":"2006-10-04T23:29:34","slug":"update-10","status":"publish","type":"post","link":"http:\/\/khrys.is-a-geek.org\/wordpress\/?p=86","title":{"rendered":"Update 1.0"},"content":{"rendered":"<p>Yeah !<\/p>\n<p>It is finally 1.0 ! So what&#8217;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 : &#8220;bloody free.fr, they are damn slow with sql requests !&#8221;.<\/p>\n<p>So I thought, perhaps I should optimize the amount of requests. It was pretty bad : I needed 3+n&#8217; requests, with n&#8217;~=n\/2 and n being the amount of rows in that table. The 3 first one are necessary, to check the user&#8217;s password, insert a hit, and collect data from the table for stats display. The n&#8217; requests are for all of those hits where the hostname was not of this format : &#8220;.xx&#8221;, or where there wasn&#8217;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&#8217;t that much. But it made me improve the readability of my code in the same time.<br \/>\n&#8211; optimized amount of requests;<br \/>\n&#8211; improved readability;<\/p>\n<p>Then, I tried it again. Damn, it is still very slow ! what the heck ??? Let&#8217;s put a few timers around the different parts of the code,  to check how much time my requests are taking.<br \/>\n&#8211; created log.txt for time control;<\/p>\n<p>OOPS, big surprise Einstein : it is not the requests (&lt;1s), but the processing that takes long : 20s ! Let&#8217;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 <em>$country[&#8220;.xx&#8221;]<\/em> and if the result isn&#8217;t a country, then it&#8217;s not in the list, meaning, the end of the hostname isn&#8217;t a 2 letter code (ie : &#8220;.com&#8221;), or I only have an IP, or it is a 2 letter code but I don&#8217;t know this one.<br \/>\n&#8211; improved the call to the &#8220;.xx&#8221; country code array;<\/p>\n<p>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 :<br \/>\n<em>$no_ip=gethostbyname($row[&#8216;hitHost&#8217;]);<br \/>\n<\/em>That&#8217;s it of courrrrse ! (with a French accent)<br \/>\nSo 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&#8217;t help. Probably one out of two cases, probably more. Good idea at the time, if only doing it wasn&#8217;t painfully slowing down everything &#8230; 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.<br \/>\n&#8211; optimized the process of information;<\/p>\n<p>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&#8217;t do much about that, and sometimes it takes no time at all, depending probably on the charge upon the server. Well, that&#8217;s what I call progress !<\/p>\n<p>And what about the user pages ? sorry guys, I didn&#8217;t have time to touch them much. Neither did I touch the &#8220;programmation&#8221; page with the doc and the zip file so far since version 0.7. But I made available the user pages though, so that <a title=\"Khrys WebCounter\" href=\"http:\/\/khrys.is-a-geek.org\/wordpress\/?page_id=85\">you can try it if you like<\/a>. The same link can be found on the left hand side of this page, just under <strong>Home<\/strong>, you&#8217;ll find <strong>Khrys WebCounter<\/strong>. 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Yeah ! It is finally 1.0 ! So what&#8217;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 : &#8220;bloody free.fr, they are damn slow with sql requests !&#8221;. So I thought, perhaps I should optimize the amount of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_options":[]},"categories":[7,10,9],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/poMUP-1o","_links":{"self":[{"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/86"}],"collection":[{"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=86"}],"version-history":[{"count":0,"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/86\/revisions"}],"wp:attachment":[{"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=86"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=86"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/khrys.is-a-geek.org\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=86"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}