简体   繁体   English

社交网络性能-PHP

[英]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 ! 我建立了一个社交网络,在WAMP中对其进行了测试,结果显示,单人使用将近1500条SQL进行了大约30分钟的会话和50次页面浏览!

[ 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 ] [我未使用ZEND或APC或MEMCACHED,最重的页面在0.25秒的配置512 MB RAM,AMD 1.81GHz内加载]

Q-> is it ok or i need to less the number of SQL ? Q->可以,还是我需要减少SQL的数量?

there are 2 tables PARENT and CHILD Structure of PARENT table PID [primary key] ... ... 有2个表PARENT和CHILD PARENT表的结构PID [主键] ... ...

Structure of CHILD table ID [primary key] PID ... ... CHILD表ID [主键] PID的结构... ...

i've not used Foreign Key, but deleting on PARENT also deletes from CHILD and i made this in PHP/SQL 我没有使用外键,但是在PARENT上删除也从CHILD中删除,我在PHP / SQL中做到了

Q-> is it ok or i should go for FOREIGN KEY for better performance ? Q->可以,还是我应该选择FOREIGN KEY以获得更好的性能?

In PHP i can config how much memory PHP gonna eat Q-> can i also do it with MySQL ? 在PHP中,我可以配置PHP要吃多少内存Q->我也可以在MySQL中做到吗? [ i am using WAMP,and need to monitor the social network's performance in bottle neck condition ! [我正在使用WAMP,并且需要在瓶颈条件下监视社交网络的性能! ] ]

No-one can say if an arbitrary number of SQL queries is OK : 没有人可以说任意数量的SQL查询是否可以

  • 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) 这取决于您计划拥有多少个并发用户(一次只有一个用户,您的应用程序可能比给定瞬间有100个用户快得多)
  • ... ...

Basically : do some benchmarks, using tools such as ab / siege / Jmeter ; 基本上:使用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). 通常,每页30个SQL查询是合理的(考虑到某些CMS的实际情况,实际上这是相当低的)。 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. 有关配置MySQL内存使用情况的信息,请参见手册第7.11.4.1 How MySQL Uses Memory . MySQL如何使用内存

I'd agree with Pascal and Oswald - esp. 我同意Pascal和Oswald-尤其是。 on testing with JMeter or similar to see if you really do have a problem. 使用JMeter或类似产品进行测试,以查看您是否确实有问题。

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. 如果您要调整MySQL的目标是引入人为的瓶颈来测试应用程序,那么我会小心地从这些测试中推​​断出来。 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. 如果有什么低调的结果,我会减少SQL查询的数量,但是每页30个查询并不过分。 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. 如果您准备好扩展到Facebook级别,我认为将每页的查询从30个减少到28个不会有太大帮助-您需要准备在多个数据库之间划分应用程序,引入缓存并购买更强大的功能硬件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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