Go Back   Pligg CMS Forum > Pligg Help > General Help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-09-2007, 04:41 PM
MicroBerto's Avatar
Casual Pligger
 
Join Date: Oct 2006
Posts: 50
Thanks: 14
Thanked 16 Times in 5 Posts
Post IP Address Database Storage

Hi all,

We have seen some issues with some database tables (mainly pageviews) getting too large and out of control. Some fixes have been made and helped, but I'd like to go further and discuss IP Address Storage.

Currently, Pligg uses VARCHARs to store IP address. This means that, at worst, each IP address is going to store 15 bytes of data (123.567.901.345 if you count numbers and dots). This adds up to a LOT of wasted space when we log every single profile/story/out pageview.

What is often done instead of this is to use INT UNSIGNED, and use built-in functions to do conversions to integer for us. This takes up 4 bytes -- significant savings.

The functions:
  1. INET_ATON()

    Let's say we get an IP Address: $ip_address = $_SERVER['REMOTE_ADDR'];

    When submitting this into the database, what you need to do is this:

    PHP Code:
    $query "INSERT INTO votes (vote_ip) VALUES (INET_ATON('$ip_address'))"
    And then the string IP gets formatted into UINT
  2. INET_NTOA()

    Now we need to get it out.

    PHP Code:
    $query "SELECT INET_NTOA(pv_user_ip) FROM pageviews WHERE pv_type = 'profile' DESC LIMIT 1"// (or whatever...)
    $result $db->query($query); // or however you do your queries 
    And now $result will have the text format back to you.

Files that would need to be changed:
  1. live2.php
  2. out.php
  3. register.php
  4. possibly story.php and user.php (they don't seem to be writing to the DB, just checking an IP)
  5. install/installtables.php
  6. install/upgrade.php (this might take some functions to run through all stored IP addresses, get them into an array, change the table, reformat the IP, and store them back in)
  7. libs/votes.php
  8. libs/pageview.php

References:
  1. MySQL Misc Functions
  2. Arjen's Journal - Storing IP Addresses

At a savings of up to 11 bytes per every vote and every time someone clicks on something, I think this is worth the work.

Let me know what you think, I'm willing to help with most of these.

Cheers,
berto
Reply With Quote
The Following 4 Users Say Thank You to MicroBerto For This Useful Post:
  #2 (permalink)  
Old 04-09-2007, 05:39 PM
kbeeveer46's Avatar
Pligg Developer/Admin
Pligg Version: 0
Pligg Template: none
 
Join Date: Jun 2006
Location: Muncie, Indiana
Posts: 3,547
Thanks: 254
Thanked 649 Times in 513 Posts
Thanks for this. You made it easy for the devs to make the changes needed. Now if all the threads were like this :P
__________________
I accept donations for my time helping users like you on the forum and IRC.
Reply With Quote
  #3 (permalink)  
Old 04-09-2007, 05:46 PM
Casual Pligger
 
Join Date: Mar 2007
Posts: 80
Thanks: 5
Thanked 2 Times in 2 Posts
Also, turn the MySQL cache off for the pageview table. This is very important from a performance standpoint.
Reply With Quote
  #4 (permalink)  
Old 04-09-2007, 11:31 PM
dollars5's Avatar
Pligg is my love :)
 
Join Date: Dec 2006
Location: India
Posts: 2,154
Thanks: 290
Thanked 266 Times in 177 Posts
Thanks m8, saving 4bytes per record is a great thing as this is a table that will get growing real fast. I hope this has already made its way to the SVN code.
Reply With Quote
  #5 (permalink)  
Old 02-12-2008, 11:27 PM
dennis's Avatar
Pligg Donor
Pligg Version: 9.8.2
Pligg Template: 9.8.2
 
Join Date: Dec 2007
Location: Silicon Valley
Posts: 12
Thanks: 2
Thanked 0 Times in 0 Posts
Send a message via Yahoo to dennis
future releases

Is there any plan to migrate the dB tables to use unsigned int(4)? I've prep'd a regEx that will convert the dB -- so that part is covered..
Reply With Quote
  #6 (permalink)  
Old 03-08-2008, 10:36 AM
netwb's Avatar
Casual Pligger
Pligg Version: 9.8
Pligg Template: Yget - Convergence - GarrX
 
Join Date: Dec 2006
Location: Bruxelles
Posts: 63
Thanks: 20
Thanked 25 Times in 11 Posts
THE IP adress is enable for the register?

Quote:
Originally Posted by MicroBerto View Post
Hi all,

We have seen some issues with some database tables (mainly pageviews) getting too large and out of control. Some fixes have been made and helped, but I'd like to go further and discuss IP Address Storage.

Currently, Pligg uses VARCHARs to store IP address. This means that, at worst, each IP address is going to store 15 bytes of data (123.567.901.345 if you count numbers and dots). This adds up to a LOT of wasted space when we log every single profile/story/out pageview.

What is often done instead of this is to use INT UNSIGNED, and use built-in functions to do conversions to integer for us. This takes up 4 bytes -- significant savings.

The functions:
  1. INET_ATON()

    Let's say we get an IP Address: $ip_address = $_SERVER['REMOTE_ADDR'];

    When submitting this into the database, what you need to do is this:

    PHP Code:
    $query "INSERT INTO votes (vote_ip) VALUES (INET_ATON('$ip_address'))"
    And then the string IP gets formatted into UINT
  2. INET_NTOA()

    Now we need to get it out.

    PHP Code:
    $query "SELECT INET_NTOA(pv_user_ip) FROM pageviews WHERE pv_type = 'profile' DESC LIMIT 1"// (or whatever...)
    $result $db->query($query); // or however you do your queries 
    And now $result will have the text format back to you.

Files that would need to be changed:
  1. live2.php
  2. out.php
  3. register.php
  4. possibly story.php and user.php (they don't seem to be writing to the DB, just checking an IP)
  5. install/installtables.php
  6. install/upgrade.php (this might take some functions to run through all stored IP addresses, get them into an array, change the table, reformat the IP, and store them back in)
  7. libs/votes.php
  8. libs/pageview.php

References:
  1. MySQL Misc Functions
  2. Arjen's Journal - Storing IP Addresses

At a savings of up to 11 bytes per every vote and every time someone clicks on something, I think this is worth the work.

Let me know what you think, I'm willing to help with most of these.

Cheers,
berto
THANKS FOR THE solution but the THE IP adress is enable of the database to the register users? yes of no?
thanks
__________________
Bruxello.com l Europeanpainting.eu l
Reply With Quote
Reply

Thread Tools
Display Modes
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Similar Threads
Thread Thread Starter Forum Replies Last Post
FYI - Strange email address in register.php nzbullet General Help 0 01-09-2008 03:22 AM
Friendly Database Unavailable Error Message LeoNel Suggestions 2 09-09-2007 09:19 PM
Database argh2xxx Bug Report 4 06-26-2007 10:04 PM
Database name, username, password = what?!?! starguy Installation and Upgrade Help 4 06-10-2007 03:29 AM
Documenting, Diagramming, and Critiquing the Pligg Database MicroBerto General Help 4 03-31-2007 04:46 PM


Search Engine Friendly URLs by vBSEO 3.2.0