Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject:
PostPosted: Sun Jan 10, 2010 10:55 am 
Offline
Senior Newbie

Joined: Wed Jul 29, 2009 12:34 pm
Posts: 10
Website: http://www.simonbyholm.com
Location: Finland
I though that the key_len would need to be 8 instead of 4 if the whole index on keywordid_score is used, but the missing Using filesort means index is used.

I can't just understand how reading 100 rows of indexed data can take 30second even if completely disk bound.


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 8:51 am 
Offline
Senior Newbie

Joined: Tue Mar 03, 2009 4:12 pm
Posts: 5
These are random reads, the index only helps you to avoid full table scan.

I'm no expert, but here's a couple things I would look into:

* Is your mysql db config allowing it to use maximum of the available memory?
* Does your index fit into memory?
* If you are using InnoDB, can you tolerate relaxing ACID properties on your updates? Each write uses "no OS/disk cache buffering" system calls under default config. Using InnoDB's transactions also means each update actually means ~ 3x disk writes (2x transcation log, 1x table update).
* Buy and read High Performance Mysql (2nd edition)


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 11:46 am 
Offline
Senior Newbie

Joined: Wed Jul 29, 2009 12:34 pm
Posts: 10
Website: http://www.simonbyholm.com
Location: Finland
I have configured half available memory to mySql index as I read the other half is needed for disk buffers (and php and apache). And no the index does not fit into memory.

I ordered High Performance Mysql (2nd edition) from Amazon, it looks like a good read in this case.

I read there's differences between using text and varchar type, I'm going to investigate that furthar as it could have a major impact on case to where I read and write a 2KB text block a lot.

I just have that feeling that reading, updating and then writing 400 2KB text block should not take 60 seconds even if completely disk bound.

I changed REPLACE INTO to INSERT .. ON DUPLICATE KEY UPDATED for the text block as I read it should be faster. I didn't notice any speed difference though.

Simon


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 12:28 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
sbyholm wrote:
Code:
$query = "SELECT * from " . $this->dbprefix . "keywordindex where keywordid='" . $keyword_id . "' order by score desc limit " . $limit . ";";


Actually I found the problem with that query now, it's not using the index for the order by part only for the select. I don't quite understand though why it's not using the index.

This is the explain output

Code:
EXPLAIN SELECT * FROM `sbs_keywordindex` where keywordid=20 order by score desc limit 100

id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    sbs_keywordindex    ref    keywordid    keywordid    4    const    92347    Using where


Any ideas, anyone?


If the key length is 4, that'd be the size of a 32-bit integer. Are you sure that it isn't just using your primary key as the index?


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 12:38 pm 
Offline
Senior Newbie

Joined: Wed Jul 29, 2009 12:34 pm
Posts: 10
Website: http://www.simonbyholm.com
Location: Finland
Code:
EXPLAIN SELECT *
FROM sbs_keywordindex
ORDER BY keywordid DESC , score DESC
LIMIT 100



Generates this

Code:

id    select_type    table    type    possible_keys    key    key_len    ref    rows    Extra
1    SIMPLE    sbs_keywordindex    index    NULL    keywordid    8    NULL    81448071    



key_len = 8

Anyway I found a solution to the second one of my slow queries

Quote:
The update means reading sitedata which is a 2KB text string, parsing it, updating it and writing the 2KB string back to the database. If ther's 400 keywords in a webpage it means read/write of 400 2KB records.


The speed to execute that increased by a factor of 3 by changing the table structure from

[keywordid INT PRIMARY] [sitelist TEXT]

to this

[keywordid INT PRIMARY] [sitelist VARCHAR(2800)]

That's nice


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 12:39 pm 
Offline
Senior Newbie

Joined: Wed Jul 29, 2009 12:34 pm
Posts: 10
Website: http://www.simonbyholm.com
Location: Finland
Disk IO also dropped to half, meaning I get 6 times the speed/disk IO cycles with the new structure.


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 2:33 pm 
Offline
Senior Newbie

Joined: Tue Mar 03, 2009 4:12 pm
Posts: 5
Are your tables InnoDB or MyISAM?


Top
   
 Post subject:
PostPosted: Mon Jan 11, 2010 3:19 pm 
Offline
Senior Newbie

Joined: Wed Jul 29, 2009 12:34 pm
Posts: 10
Website: http://www.simonbyholm.com
Location: Finland
MyISAM


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group