Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4017648
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:53:13+00:00 2026-05-20T09:53:13+00:00

I’m wondering what’s better for my server (speed, etc), considering CPU, bandwidth and diskspace

  • 0

I’m wondering what’s better for my server (speed, etc), considering CPU, bandwidth and diskspace usage.

Currently my server is about to explode, too much MySQL/PHP requests, and so on, that’s why I’m optimizing my application (discussed in this question: Best way to scale data, decrease loading time, make my webhost happy).

Now, what’s the best solution to decrease CPU, bandwidth and diskspace usage?

1) Fetch a single big record from a
table (100.000+ records, let’s say
20kb/record) and handle the fetch with
PHP => only 1 request, but the result
may cause a heavy server load?

2) Fetch multiple small records from a
table (1.000.000+ records, let’s say
1kb/record) => significant more MySQL
requests needed to get the same result
as the result in method 1

Method 1 will cause the database to become lots of GBs (10+). Using method 2 the database will be smaller, but I’m not sure about the effect of running a lot of queries on the performance of my application?

Returning a mysql_result() from a table of 1.000.000+ records takes more time, because it needs to scan all the rows for a specific records?

Hope you can tell me what method is better to decrease CPU, bandwidth and diskspace usage!

Edit

I currently have one table: facebook_id, friends_json.
In friends_json, the uid AND name of every friend of this facebook_id user is stored. Using this method, every record is about 10kb. Once this record is requested, I don’t have to do extra requests to fetch the name of a friend: this is already included in the friends_json.

My question is whether it is better to only store the friends’ uids in the friends_json, so that for each friend I have to run a query to another table (friends_names) to fetch the name of this friend from this table (if not available, request it from Facebook). This second method saves diskspace, but I really have to do a large amount of requests before I can show the user a result.

The goal is that I have to compare the list of friends in my database with a current list of friends. If a user deleted his/her Facebook profile, I can’t request the corresponding name anymore, that’s why I have to save the names in my database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T09:53:13+00:00Added an answer on May 20, 2026 at 9:53 am

    Since the question is not clear enough (or I cant understand it correctly) I would assume that you have 1 table having 2 columns : facebook_id, friends_json and you are requesting all the friends of friends. This is the worst case I can ever think of. still all you have to do is 2 simple query :

    1. get the subject’s with 1 index hit, then get uid’s from json decoding it
    2. get all friend’s friend list with an “in” query using the ids, then push them all into a map to get rid of duplicates.

    none of the queries above needs to scan whole table (and its the worst case)

    if you can give more info about your table structure and your goal (what you want to retrieve from that data) we can help more.

    Edit: Nothing can save your server if you have to do a table scan in every hit.

    Edit:

    I currently have one table:
    facebook_id, friends_json. In
    friends_json, the uid AND name of
    every friend of this facebook_id user
    is stored. Using this method, every
    record is about 10kb. Once this record
    is requested, I don’t have to do extra
    requests to fetch the name of a
    friend: this is already included in
    the friends_json.

    My question is whether it is better to
    only store the friends’ uids in the
    friends_json, so that for each friend
    I have to run a query to another table
    (friends_names) to fetch the name of
    this friend from this table (if not
    available, request it from Facebook).
    This second method saves diskspace,
    but I really have to do a large amount
    of requests before I can show the user
    a result.

    The goal is that I have to compare the
    list of friends in my database with a
    current list of friends. If a user
    deleted his/her Facebook profile, I
    can’t request the corresponding name
    anymore, that’s why I have to save the
    names in my database.

    As long as you get the result with hitting index the size of table or the row wouldn’t affect as much as you think. And a join just to get names when you keep uid’s normalized is not the way to go. Eighter you keep a “users” table with “uid, name” columns and friendship table “uid1, uid2” or you have normalized data including both uid and name. And about the new and old friendlist comparison, you should do it in php anyway using uid’s (not the names). get friendlist from facebook, compare it with current friendlist, find the differences and apply to database. In this case you shouldn’t have to table scan at any point of your application.

    Here is the normal way to do it (without json):

    fb_users table : uid, name, is_app_user (PK: uid)
    fb_friends table : uid1, uid2 (PK: uid1, uid2)

    get friends sql query :

    SELECT ff.uid1, fu.name FROM fb_friends ff
    LEFT JOIN fb_users fu ON ff.uid1 = fu.uid
    WHERE ff.uid2 = $FBID 
    UNION
    SELECT ff.uid2, fu.name FROM fb_friends ff
    LEFT JOIN fb_users fu ON ff.uid2 = fu.uid
    WHERE ff.uid1 = $FBID
    

    and to add users you can do a neat trick to update the name everytime for name changes (which is used most of the time) :

    INSERT INTO fb_users(uid,name) 
    VALUES 
    ($FBUD1, $FBNAME1), 
    ($FBUD2, $FBNAME2) 
    ...
    ON DUPLICATE KEY name = VALUES(name)
    

    and to add friends you can do a trick aswell so you don’t have to worry about having A B and B A at the same time :

    INSERT IGNORE INTO fb_friends(uid, uid1) VALUES(" . min($uid, $uid1) . ", " . max($uid, $uid1) . ");
    

    these are just tricks if you decide to keep your data relational, but I would suggest keeping it normalized anyway. your json method is what is used in most cases, and don’t worry about space alot, since the data size is usually not the thing that blocks the servers, its the way you request data (code) and the way you grab it(sql queries) is where you should tune.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am currently running into a problem where an element is coming back from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.