Jump to content

Recommended Posts

Hi All

I have a site that holds over 900k of products. I am searching on my db and its taking 10 seconds to search products and bring back results. I wondered if i stored the data in the ram the results would be instantanious.

 

Does anyone have any experience or could point me in the right direction of how to do this.

 

In an ideal world i would like the rsults to come back in aroun1/2 seconds.

 

Thanks for the help and advice in advance :)

Link to comment
https://forums.phpfreaks.com/topic/276388-using-php-to-store-and-call-data-in-ram/
Share on other sites

Most likely, your problem is due to the database design and the queries used. Have you indexed the relevant fields? Perhaps you can post the query as well.

 

EDIT: And I really, really hope you are not running any queries in loops.

Edited by Psycho

Hi All

I have a site that holds over 900k of products. I am searching on my db and its taking 10 seconds to search products and bring back results. I wondered if i stored the data in the ram the results would be instantanious.

 

Does anyone have any experience or could point me in the right direction of how to do this.

 

In an ideal world i would like the rsults to come back in aroun1/2 seconds.

 

Thanks for the help and advice in advance :)

 

 

 

It sounds like a databse design/query issue.  Without some information about your design, and the queries you are doing, there is no way to help you but I can offer a few ideas to get you started:

 

-You didn't state what database you are using, but I'm going to assume it's mysql. Step 1 should be to run EXPLAIN EXTENDED on your queries from the mysql command line tool (or phpMyAdmin).

This will help you understand what your query is actually doing (and it's most likely tablescanning and looking at your whole table for every single query)

 

-If your tables are using myisam storage engine move to innodb. Innodb has a true data cache component, so if the server has sufficient memory, it can keep much if not all the dataset in memory all the time.

 

-If you have LIKE queries which include wildcard-something-wildcard, those are never going to use an index.  For example, I often see people doing this:

SELECT * FROM TABLE WHERE somecolumn LIKE "%criteria%";
Those types of queries will NEVER be performant, because a btree index can not be used.

 

Full text based searches really need to be done with a fulltext search system. Mysql does have a fulltext search index type, that might get you what you need, but most large sites use solr or sphinx, or if on aws, elastic search.

 

Most sites use some sort of caching system to store the results of queries in memory. Memcache and Redis are two of the most popular solutions, and there is also the option of using APC for a single server that has plenty of available RAM.

 

In all cases, you really need to understand the resources available to you, as far as server os, RAM, db configuration etc.

Hi

 

this is the query

SELECT p.*, a.payout_level, a.buttonimage, a.smalldesc,a.companyname, v.* FROM products p left join advert a on p.advertId = a.id AND a.network='4' left join (  Select min(id), merchantid, code, value from vouchers group by merchantid ) as v on a.id = v.merchantid  WHERE p.prod_name LIKE '%glass%'   And  p.cat like 'Glassware'  order by p.fee asc LIMIT 0, 6

 

All the tables have been optimised for indexing

Could you explain this query ?

 

Example:

 

$query = "EXPLAIN SELECT p.*, a.payout_level, a.buttonimage, a.smalldesc,a.companyname, v.* FROM products p 
    left join advert a on p.advertId = a.id AND a.network='4' 
    left join ( Select min(id), merchantid, code, value from vouchers group by merchantid ) as v on a.id = v.merchantid 
    WHERE p.prod_name LIKE '%glass%'   And  p.cat like 'Glassware'  order by p.fee asc LIMIT 0, 6";

1. Do you really need LEFT JOINS? They are less efficient than a normal INNER JOIN.

 

2. Instead of using LIKE here, use an equal comparison insead

 

  And p.cat like 'Glassware'

 

3. No need to use a sub-query, just JOIN on the other tables and use group BY on the results

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.