简体   繁体   English

注册用户总数的基于性能的计数

[英]Performance based count for total number of users registered

What is the best way to keep track of the TOTAL NUMBER OF USERS REGISTERED in terms of performance?在性能方面跟踪注册用户总数的最佳方法是什么?

select count(id) from user_table

OR或者

  • Create a table which stores number of users registered and every time a new user registers, increment the value by 1.创建一个表来存储注册的用户数,每次有新用户注册时,将值加 1。

The total number of users registered will be displayed on the Admin Dashboard.注册的用户总数将显示在管理仪表板上。

If there is any other way to do it, i would love to know.如果有任何其他方法可以做到这一点,我很想知道。

The count exist to accomplish your request: count存在以完成您的请求:

Select count(id) from user_table

If you create another table, at every new registration you need to alter the table and increment the value, costing one operation every time a user register.如果您创建另一个表,则在每次新注册时,您都需要更改该表并增加值,每次用户注册时都会花费一次操作。

Don't create another table for that.不要为此创建另一个表。

Just do Select count(id) from user_table it's just fine就做Select count(id) from user_table就好了

I have already commented on this but i think that posting it as an answer would fit better.我已经对此发表了评论,但我认为将其发布为答案会更合适。

When it comes to performance, the first think one might think of is "Caching", you can simplay store the total number of users in a caching object "something like memcached " and read from it instead of database, when a new user registers you may reset the value of that object with the new one.说到性能,第一个想到的可能是“缓存”,当新用户注册时,您可以简单地将用户总数存储在缓存对象“类似memcached 的东西”中,并从它而不是数据库中读取可以用新的值重置该对象的值。

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

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