简体   繁体   English

极慢的性能结构

[英]Very slow performance structure

Since I have no errors I don't know if this is the right place to ask this question, if it's not, please point me to the right forum. 由于我没有错误,所以我不知道这是问这个问题的正确地方,如果不是,请指出正确的论坛。 Any way... 随便...

I am working on a social network project and now it runs really slow, some pages take like 5 to 15 seconds to load. 我正在一个社交网络项目上工作,现在它运行速度非常慢,某些页面的加载时间约为5到15秒。 There is a "cache" structure but whoever did this, didn't use to already build in Cache from the c# .net, instead, they created a static List<object> as the cache of the system. 有一个“缓存”结构,但是无论这样做的人是谁,都没有使用它从c#.net中构建Cache ,而是创建了一个静态List<object>作为系统的缓存。 Even tought is not right, i can deal with that... 甚至Hardt也不对,我可以解决这个问题。

The problem is, on every page request, I have to load the user data from this cache wich is quite big, and the user structure is quite big as well so I was wondering, stead of loading the user data from cache everytime a page is requested I will create Some sessions with the most used data that every page requires, like, photo, name, nickname, id, and than when I need to load anyother type of data from user that is not common, I request it from the cache... 问题是,在每个页面请求上,我都必须从此cache加载用户数据,而且用户结构也很大,所以我想知道,而不是每次在页面加载时都从缓存加载用户数据请求,我将使用每个页面需要的最常用数据(例如照片,姓名,昵称,ID)创建一些会话,然后当我需要从用户中加载不常见的其他任何类型的数据时,我从缓存中请求它...

I don't know if this is the right aproach not if this is the right place to ask it, but I really need to solve this problem pretty bad. 我不知道这是否是正确的方法,不是问这个地方是否正确,但是我真的很想解决这个问题。 so I would like some advices from the experts out here. 因此,我想请专家们提供一些建议。

Part of the performance problem may be needing to scan the cache for items. 性能问题的一部分可能是需要在缓存中扫描项目。 A Dictionary might be better, since you could retrieve items by key. 字典可能更好,因为您可以按键检索项目。 This is a closer implementation to the native cache structure. 这是与本机缓存结构更接近的实现。

Sessions are bad for scalability of a website. 会话不利于网站的可扩展性。 If you plan on this being as big as facebook or something, using sessions for caching will kill you 如果您计划将其设置为与Facebook一样大,则使用会话进行缓存会杀死您

See this other related question : 参见其他相关问题:

What is a good way to store large temporary "session" data in a web application 什么是在Web应用程序中存储大型临时“会话”数据的好方法

and another decent question 另一个体面的问题

Why is it a bad idea to use Session to store state in high traffic websites? 为什么使用Session在高流量网站中存储状态不是一个好主意?

Agree with Jason +1 同意杰森+1

From you comment user objects have a key (ID). 根据您的评论,用户对象具有一个密钥(ID)。

Dictionary is way way faster if you have a key. 如果您有钥匙,字典会更快。 Furthermore override gethash and equals if your objects have a natural key that can be expressed as Int32. 此外,重写gethash并等于您的对象是否具有可以表示为Int32的自然键。 A dictionary lookup against 10,000 should be milliseconds. 针对10,000的字典查找应为毫秒。

A keyed collection sound like what you needs. 键控收藏听起来像您所需要的。 With a keyed collection one of the properties (ID) is the key. 对于键控集合,属性(ID)之一就是键。
keyedcollection 密钥集合

If this is a static list I would go dictionary over a database. 如果这是一个静态列表,我将通过数据库进行词典搜索。 Since you have a single key dictionary will beat database. 由于您只有一个字典,因此字典将击败数据库。 If it was composite key then you would have to go with a database for an indexed lookup. 如果它是复合键,那么您将不得不使用数据库进行索引查找。

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

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