General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 28th, 2003, 09:01 PM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
speeding up my sql

Hi guys,
not sure if this should go in this forum or a (my)sql one, but damn it i'm using php, anyways..

I've written a (simple) hits tracker for my site, it records the Date, VisitorIP, Page Hit and Page Refered From, this is all stored in one big table:
hit_id int(10) unsigned MUL auto_increment
hit_time timestamp(14)
hit_host varchar(255)
hit_page varchar(255)
hit_refer varchar(255)
hit_ip varchar(15)
(not idea whi hit_id is MUL not PRI, anyone understand this and is it significant)
Everypage that is hit puts the appropriate data in to the database, then it coes to the viewing!
The page that views all the hits is very slow, sometimes 3 or 4 seconds (for about 1200 records), all it does is selects this data from the database and runs through a while loop, displaying it in a lovely table, with a total number of hits and time taken for the script to execute.

The SQL i am using is 'SELECT * FROM php_hits WHERE hit_time > ' . $date . ' ORDER BY hit_time ASC' where $date is the date to limit it all by. i.e. you want all hits since december $date = 20031201000000 (i think).

I also play with the data (a little) in the while loop, converting timestams to readable messages (28 December 2003 - 16:22 for example), ripping the page from the hit url, taking of http://www. from all referring pages and the like, could this be the biggie slowing me down? I am using my own fuctions for this not any of PHPs and there may be a better way of doing this.

My current thinking is either, there is a better way to do the tables / SQL that i'm not aware of, my functions in the loop are slowing it all down (when they are executed 1000+x), and i should probably do something about that, like ripping the page from the url when put INTO the db not taken OUT OF it! (i'm kinda lazy and that sounds challenging!)

So if anyone has any suggestions on how to make it quicker (not using go faster stripes pls!) then it would be much appriciated.

Sorry about the long post but i have just improved my code quite a bit but am v. sure the are ways to make it 100x better,
Cheers,

Matt

Reply With Quote
  #2  
Old December 29th, 2003, 08:06 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
I'd say you'd probably want hit_id to be a primary key. How it became a MUL, I can't guess. Did you create it that way?

You might try indexing the hit_time field. I don't know that that'd give you a big performance increase, though.

It might help you out to use mysql's DATE_FORMAT function to format some of the dates, and I would suggest stripping the page from the URL on the way into the database. Perhaps you could try using getenv("REQUEST_URI") to insert into the database -- that should give you everything after the domain name and require no up-front (or back-end) processing.

Reply With Quote
  #3  
Old December 29th, 2003, 10:42 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
yeah i was sure i made hit_id the primary key, but i guess not!

I think you are on a winner with the inserting without domains and just displaying it, should take a chunk of processing out of it, especially with it being in the loop and all, i'll give it a go, and have a look at DATE_FORMAT

Reply With Quote
  #4  
Old December 29th, 2003, 07:14 PM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
what does indexing the hit_time field do? how would i do it?

Reply With Quote
  #5  
Old December 30th, 2003, 08:58 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Indexing the hit_time field may speed up queries on that field. I'm no expert on indexing, so I can't certify that it will or anything. I never can recall the syntax for adding an index off the top of my head. Check out mysql.com and search on either the alter table syntax or just index.

Reply With Quote
  #6  
Old January 27th, 2004, 04:01 AM
barraca barraca is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: Spain
Posts: 4 barraca User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
If you create indexes in your database with the fields you most call you will speed up a lot the mysql acces and triggers.

Daniel.
____________________________
Webmaster of Hotel Netguide & Barcelona Guide Sites.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > speeding up my sql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT