简体   繁体   中英

Social Network Performance - PHP

i made a social network, testing it in WAMP shows almost 1500 SQL for a single person for a session of about 30 mins and 50 page views !

[ i'm not using ZEND or APC or MEMCACHED The heaviest page gets loaded within 0.25 second config 512 MB RAM, AMD 1.81GHz ]

Q-> is it ok or i need to less the number of SQL ?

there are 2 tables PARENT and CHILD Structure of PARENT table PID [primary key] ... ...

Structure of CHILD table ID [primary key] PID ... ...

i've not used Foreign Key, but deleting on PARENT also deletes from CHILD and i made this in PHP/SQL

Q-> is it ok or i should go for FOREIGN KEY for better performance ?

In PHP i can config how much memory PHP gonna eat Q-> can i also do it with MySQL ? [ i am using WAMP,and need to monitor the social network's performance in bottle neck condition ! ]

No-one can say if an arbitrary number of SQL queries is OK :

  • It depends on the complexity of those queries
  • It depends on your database's structure (indexes, for instance, play a big role)
  • It depends on the amount of data you have
  • It depends on how many concurrent users you plan to have (with one user at a time, your application will probably be way faster than with 100 users at a given instant)
  • ...

Basically : do some benchmarks, using tools such as ab / siege / Jmeter ; and see if your server can handle the load you expect on having in the next few weeks.


Using foreign keys generally doesn't help with performances (except if they force you setting indexes you'd need but wouldn't have created by yourself) : they add some extra-work on the DB side.

But using foreign keys helps with data integrity -- and having data that's OK is probably more important than a couple milliseconds, especially if you are just launching your application (which means there could be quite a few bugs) .

30 SQL queries per page is reasonable in general (actually it's quite low considering what some CMS do). On the other hand, with the information given, it is not possible to determine whether it is reasonable in your case .

Foreign keys do not improve performance. Foreign key constraints might. But they also put business logic into the persistence layer. It's an optimization.

Information about configureing the memory usage of MySQL can be found in the handbook section 7.11.4.1. How MySQL Uses Memory .

I'd agree with Pascal and Oswald - esp. on testing with JMeter or similar to see if you really do have a problem.

I would also load up the database with a few million test profiles to see whether your queries slow down over time. This should help with optimizing query performance.

If your goal for tweaking MySQL is to introduce an artificial bottleneck to test the application, I'd be careful to extrapolate from those tests. What you see with bottlenecks is that they tend to be non-linear - everything is fine until you hit a bottleneck moment, and then everything becomes highly unpredictable. You may not recreate this simply by reducing the memory of the database server.

If there's any low-hanging fruit, I would reduce the number of SQL queries, but 30 queries per page is not excessive. If you want to be prepared to scale to Facebook levels, I don't think reducing the queries per page from 30 to 28 will help much - you need to be ready to partition the application across multiple databases, introduce caching, and buy more powerful hardware.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM