1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Whis is faster - reading a text file or processing a mysql db

Discussion in 'MySQL' started by shawnecstacy, Jan 2, 2008.

  1. #1
    Hello

    Which one process faster and takes low cpu load to complete the job.

    job: lots of image links to be displayed on a page.

    1st way) write all the links in a text file per line .. and loop through that text file.

    2nd way) make a mysql table which will contain the text links..

    i want to know if the sites gets heavy traffic which one of these two method will be beneficial with respect to speed and load on server.

    Thanks.
     
    shawnecstacy, Jan 2, 2008 IP
  2. abdussamad

    abdussamad Active Member

    Messages:
    543
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    The mysql db will be a hell of a lot easier to maintain and probably a little faster than the text file.
     
    abdussamad, Jan 2, 2008 IP
  3. flippers.be

    flippers.be Peon

    Messages:
    432
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    this will depend a lot on the implementation of how you read a file - if you read the whole file in memory and then read each line, I guess it's a bit quicker then mysql as you have less overhead

    if you do a read access to disk for each next line it will be a lot slower..
     
    flippers.be, Jan 2, 2008 IP
  4. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #4
    definately reading a text file will be more fast and plus it wont put a load on ur server.

    Regards

    Alex
     
    kmap, Jan 2, 2008 IP
  5. RectangleMan

    RectangleMan Notable Member

    Messages:
    2,825
    Likes Received:
    132
    Best Answers:
    0
    Trophy Points:
    210
    #5
    The answers here don't really suffice.

    There are 2 possibilities.

    1. Server has a lot of requests...
    2. Server is slow and site is small

    In instance 1 you want mysql or another database. For instance 2 you can use a filesystem just fine.

    Keep in mind databases are in general a lot easier to deal with large selection of information. That's their purpose.
     
    RectangleMan, Jan 3, 2008 IP
  6. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Maybe there are the third solution, take these links as a variable, and serialize it into file systems.
    e.g. in php:

    The file contains:
    And in the script:
     
    hostingcoupon, Jan 3, 2008 IP
  7. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #7
    The whole point of developing databases was for their speed.

    If the text file is very small - I can't give an exact number, perhaps bellow 1000 lines - then text file is faster otherwise you should definitly go with database.

    The surrest bet: put a php timer on your page and try both ways.
     
    mahmood, Jan 3, 2008 IP
  8. shawnecstacy

    shawnecstacy Peon

    Messages:
    456
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks to all for this quality information.
    mahmood has suggested a good idea of checking by a timer ..

    its just like a gallery !!
    say i have server 1 -> contains script which displays the image on a page.
    server 2 -> contains images.

    now i have to store all the image(server 2) links on server 1 in a text file or in a database..

    But now i guess i have to go with database only becoz one thing i havnt thought before .. was that the images r in catagories.. so there must a search condition to pick up images from categories... database goes easy on this..

    rectangleman's suggestion is also good .. as yes the server will get lots of request ..

    Thanks to all others for their suggestions.. now i need to work my brain out for this job .. :)
     
    shawnecstacy, Jan 3, 2008 IP
  9. abumoosa

    abumoosa Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    for normal access , Text will be faster , fot searching also text faster , but when you have large Text file or long text you have to build your own algorithm to maintain fast searching , otherwise any database has indexing service will be much faster .
     
    abumoosa, Jan 5, 2008 IP
  10. abumoosa

    abumoosa Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    one think more , building Search engine not easy with Text file , because you have to know every data place accoiding to another ( Postition )
     
    abumoosa, Jan 5, 2008 IP
  11. petarzito

    petarzito Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    What about this approach?
    I was thinking about testing something like this...
    tks
     
    petarzito, Nov 30, 2011 IP
  12. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #12
    Third way - reading the entire text file at once (not reading a line at a time).

    Which is faster? Reading the whole text file at once.

    Which uses less CPU? That depends on the database.

    Which is easier to write, easier to maintain and better? A database.
     
    Rukbat, Dec 1, 2011 IP
  13. Digi_Tech

    Digi_Tech Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    If you are using proper query than mysql is little faster compare to the plain text file as text file will read data sequencially
     
    Digi_Tech, Dec 9, 2011 IP
  14. rajmeetbhullar

    rajmeetbhullar Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    processing a mysql db is faster than reading a text file because text editor are not generic to which will be there in it or text file can have error . So processing a sqldb is faster.this also depends upon the hosting server you are using for your website
     
    rajmeetbhullar, Dec 21, 2011 IP
  15. chandrajit1988

    chandrajit1988 Well-Known Member

    Messages:
    319
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    Articles:
    1
    #15
    Definitely processing a MySQL DB
     
    chandrajit1988, Dec 21, 2011 IP