在 ASP.NET 中缓存所有用户
我正在 ASP.NET/C# 中开发一个 Web 应用程序,该应用程序需要可扩展以处理高用户负载(可能会在网络场中运行)。因为它将迎合大量用户,大约 100 万以上,但在线用户数量将在 30K-50K 左右。我计划使用缓存(基于提供程序),并且想知道:
缓存所有用户以提高性能是一个好主意吗?我计划缓存所有其他通用数据,例如设置等,但是将所有用户缓存在内存中的效率如何?如果用户更改了他/她的个人资料,我将仅重新加载缓存中的特定用户(拥有所有用户的集合)。对这种方法有什么建议吗?
使用上述用户缓存时我需要担心锁定吗?只有用户本人才能编辑配置文件,这将是一项原子操作,尽管不同线程中会有多个读取操作。因此,在从缓存中获取用户或更新特定用户时,我应该使用锁吗?
谢谢阿西夫
I am working on a web app in ASP.NET/C# which needs to be scalable to handle the high user load (will probably run in a web farm). Since it will cater to a high number of users, around 1 Million plus, but number of online users would be around 30K-50K. I plan to use caching (provider based), and was wondering:
Is it a good idea to cache ALL users for performance? I plan to cache all other generic data, like settings etc, but how efficient would it be to cache ALL users in memory? If a user changes his/her profile, I will reload only that particular user in cache (having a collection of all the users). Any suggestions on this approach?
Do I need to worry about locking when using this above users cache? Only one editing the profile would be the user himself, that would be one atomic operation, though there will be multiple read oeprations in different threads. So while fetching users from cache, or updating a particualr user, should I use lock?
Thanks
Asif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将仅对单个用户有用的任何内容放入全局缓存中通常是一个坏主意,并且会降低性能。优化您的数据库查询,您的状态将会好得多。
作为一般经验法则,您应该只将那些从数据库获取成本高昂的内容保留在缓存中,并且不止一个用户希望立即查看该信息。比如排名前100的产品列表什么的。从数据库中获取相对便宜且仅对单个人有用的少量数据应该保留在原处。
缓存极大地增加了复杂性,在网络场中更是如此。除非绝对必要,否则不要引入不必要的复杂性。等到出现实际性能问题后再尝试解决它。
Putting anything in Global Cache that is only useful to a single user is usually a bad idea and a performance killer. Optimize your database queries, and you will be in much better shape.
As a general rule of thumb you should only keep things in cache that are expensive to get from the database, and more than one user will want to see that information at once. Such as a list of the top 100 products or something. Small amounts of data that are relatively cheap to grab from the database, and that are only useful to a single person should stay where they are.
Caching increases complexity tremendously, and even more so in a web farm. Don't introduce needless complexity unless you absolutely have to. Wait until you have an actual performance problem before trying to solve it.
缓存用户可能是一个好主意。但这取决于您要为每个用户缓存多少数据,以及从存储位置检索该数据的成本。
对于锁定 - 其他人可以编辑用户的个人资料(例如管理员)吗?这会是常见现象吗?如果是这样,您可能需要进行一些锁定。否则,如果只有用户可以编辑自己的东西,我就不会打扰。
Caching users is probably a good idea. But it depends on how much data you are going to cache for each user, and the cost of retrieving that data from wherever it is stored.
For locking - can anyone else edit a user's profile (like an admininstrator)? Would that be a common occurrence? If so, you may want to do some locking. Otherwise, if only the user can edit their own stuff, I wouldn't bother.