简体   繁体   中英

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. 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. Even tought is not right, i can deal with that...

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...

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

See this other related question :

What is a good way to store large temporary "session" data in a web application

and another decent question

Why is it a bad idea to use Session to store state in high traffic websites?

Agree with Jason +1

From you comment user objects have a key (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. A dictionary lookup against 10,000 should be milliseconds.

A keyed collection sound like what you needs. With a keyed collection one of the properties (ID) is the key.
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.

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