我的ASP.NET会话太大了吗?

时间:2022-12-03 16:55:07

In our .NET web app, we have a session object for each logged in user that is around 5-7 kilobytes. The session stores a Dictionary object that contains a couple of classes and the user's authentication token. Does this session size seem too big? I really don't know what a good size is or what good practices I should follow for sessions. Do any of you have ideas? Thanks

在我们的.NET Web应用程序中,每个登录用户都有一个大约5-7千字节的会话对象。会话存储一个Dictionary对象,该对象包含几个类和用户的身份验证令牌。这个会话规模看起来太大了吗?我真的不知道什么是好的尺寸或者我应该遵循什么样的良好做法。你们有没有想法?谢谢

5 个解决方案

#1


Only put in the session what is absolutely necessary to be in there. Otherwise, cache it or retrieve it from somewhere else using the ID's you store in the session. If it can go someplace else, chances are that's where it needs to go instead of inside your session object.

只在会议中放入绝对必要的内容。否则,使用您在会话中存储的ID来缓存它或从其他地方检索它。如果它可以去其他地方,那么它可能需要去的地方而不是你的会话对象。

#2


TheTXI and DevelopingChris have provided best practices, but here's the ultimate answer to your headline question: only you can tell if your session is too big. If you're not encountering problems with memory usage on your web servers (or with traffic between webs and state server, if you're using an external state server), your session isn't storing too much; if you are, it is.

TheTXI和DevelopingChris提供了最佳实践,但这里是您标题问题的最终答案:只有您可以判断您的会话是否太大。如果您没有遇到Web服务器上的内存使用问题(或者Web和状态服务器之间的流量,如果您使用外部状态服务器),则会话不会存储太多;如果你是,那就是。

Best practices can certainly help you resolve problems when you are, and reduce the chances of them occurring, but if what you have isn't broken you'd probably be better off spending valuable development energy on parts of the code that will affect your users or your maintainability.

最佳实践当然可以帮助您解决问题,并减少问题发生的可能性,但如果您的问题没有被破坏,您可能最好不要在代码的某些部分上花费宝贵的开发能量来影响您的用户或者你的可维护性。

#3


The general industry standard is to reduce it to as low as possible, cache the objects, and store the id's in session to go retrieve them on the next request.

一般的行业标准是将其降低到尽可能低,缓存对象,并将ID存储在会话中以便在下一个请求时检索它们。

In asp.net in general, there are problems with running a multiple box application and having to store session in the database, and then deserialize it into objects.

在asp.net中,运行多盒应用程序并且必须在数据库中存储会话,然后将其反序列化为对象时存在问题。

If you end up going this way, its more of a hit to have to hit the database for xml and then deserialize it than to hit the record itself.

如果最终以这种方式运行,那么必须为xml命中数据库然后反序列化它而不是命中记录本身。

#4


It's going to depend on your scalability requirements. 5-7K * 1000 concurrent sessions = 57 MB. Assuming you have a decent amount of RAM, you should be fine. That said, you should be very careful about what is being stored in session and avoid storing what isn't absolutely necessary.

这取决于您的可扩展性要求。 5-7K * 1000个并发会话= 57 MB。假设你有相当数量的RAM,你应该没问题。也就是说,您应该非常小心会话中存储的内容,并避免存储非绝对必要的内容。

#5


Not if you need it. You should step through it and see what you can more to the Cache or leave in the database.

如果你需要的话就没有。您应该单步执行它,看看您可以更多地使用缓存或保留在数据库中。

#1


Only put in the session what is absolutely necessary to be in there. Otherwise, cache it or retrieve it from somewhere else using the ID's you store in the session. If it can go someplace else, chances are that's where it needs to go instead of inside your session object.

只在会议中放入绝对必要的内容。否则,使用您在会话中存储的ID来缓存它或从其他地方检索它。如果它可以去其他地方,那么它可能需要去的地方而不是你的会话对象。

#2


TheTXI and DevelopingChris have provided best practices, but here's the ultimate answer to your headline question: only you can tell if your session is too big. If you're not encountering problems with memory usage on your web servers (or with traffic between webs and state server, if you're using an external state server), your session isn't storing too much; if you are, it is.

TheTXI和DevelopingChris提供了最佳实践,但这里是您标题问题的最终答案:只有您可以判断您的会话是否太大。如果您没有遇到Web服务器上的内存使用问题(或者Web和状态服务器之间的流量,如果您使用外部状态服务器),则会话不会存储太多;如果你是,那就是。

Best practices can certainly help you resolve problems when you are, and reduce the chances of them occurring, but if what you have isn't broken you'd probably be better off spending valuable development energy on parts of the code that will affect your users or your maintainability.

最佳实践当然可以帮助您解决问题,并减少问题发生的可能性,但如果您的问题没有被破坏,您可能最好不要在代码的某些部分上花费宝贵的开发能量来影响您的用户或者你的可维护性。

#3


The general industry standard is to reduce it to as low as possible, cache the objects, and store the id's in session to go retrieve them on the next request.

一般的行业标准是将其降低到尽可能低,缓存对象,并将ID存储在会话中以便在下一个请求时检索它们。

In asp.net in general, there are problems with running a multiple box application and having to store session in the database, and then deserialize it into objects.

在asp.net中,运行多盒应用程序并且必须在数据库中存储会话,然后将其反序列化为对象时存在问题。

If you end up going this way, its more of a hit to have to hit the database for xml and then deserialize it than to hit the record itself.

如果最终以这种方式运行,那么必须为xml命中数据库然后反序列化它而不是命中记录本身。

#4


It's going to depend on your scalability requirements. 5-7K * 1000 concurrent sessions = 57 MB. Assuming you have a decent amount of RAM, you should be fine. That said, you should be very careful about what is being stored in session and avoid storing what isn't absolutely necessary.

这取决于您的可扩展性要求。 5-7K * 1000个并发会话= 57 MB。假设你有相当数量的RAM,你应该没问题。也就是说,您应该非常小心会话中存储的内容,并避免存储非绝对必要的内容。

#5


Not if you need it. You should step through it and see what you can more to the Cache or leave in the database.

如果你需要的话就没有。您应该单步执行它,看看您可以更多地使用缓存或保留在数据库中。