By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
access_time 12 years ago visibility360 comment 0 language中文

.net中默认的会话状态是存储在内存中的,当一个网站的用户数量少或者说 同时访问的人数不多的时候可能还没什么,但是一旦用户在线人数过多的时候则会出现瓶颈了,于是本文采用SQlite数据库来实现这个提供程序

/// <summary>
    /// Juice网站会话状态数据存储提供类
    /// </summary>
    public sealed class SQLiteStoreProvider : SessionStateStoreProviderBase
    {}

只要类继承SessionStateStoreProviderBase 并重写其中的抽象方法即可,由于msdn里边有,所以这里不再赘述

最后再web.config中配置为

<system.web>
    <sessionState mode="Custom" cookieless="UseDeviceProfile" customProvider="JuiceSSExpress">
      <providers>
        <add name="JuiceSSExpress" type="Juice.Core.SessionState.SQLiteStoreProvider"/>
      </providers>
    </sessionState>

我采用的是将session数据串行化为二进制然后保存在数据库中,在提取的Session数据的时候用反串行二进制的方法,但是这样用起来却比我以前直接将会话状态数据保存在内存中慢了很多

以前只需要0.0003秒而现在却需要0.2786183s

当然这是因为我这两种情况只有我一个人访问所以还无法对比出来

所以正在用Web压力测试工具测试 等会把结果弄出来

同时正在考虑横向改变数据库提供方式比如用SqlServer和Access数据库再测试下

也正在考虑把纵向改变串行化的方式,看能不用用其他的串行化的方式来提高下性能

也同时在考虑用Cache来保存会话状态,不过很多人说这样做是完全错误的,以为Cache会随着断电等的丢失,而且Cache是全局的,所以只是暂时一个想法而已,而我自己也认为有时一些新的发现可能正是在那些别人认为不可能或者错误的地方

当然之所以做这么多的探讨,目的只是为了我的系统能适合更多的用户

因为有的站长没有sqlserver 所以是不能用sqlserver来提供会话状态存储数据的

有的站长只能用Access和Sqlite这种轻量级的但相对来说是免费的数据库,如果他们的用户多的话,所有数据保存在内存中估计会慢,所以正在探讨一种 数据库与SessionState提供程序的折中优化方式....


info Last modified by Raymond at 6 years ago * This page is subject to Site terms.

More from Kontext

visibility 13649
thumb_up 0
access_time 6 years ago

SQL Server Compact 4.0 (CE 4.0) is a free SQL Server embedded database ideal for building standalone and occasionally connected applications for mobile devices, desktops, Web clients and others. In one of my projects, I used it as the database for logging errors, which assumes the errors will onl...

open_in_new View open_in_new SQL Server

visibility 684
thumb_up 0
access_time 6 years ago

SQL Server provides a batch of great features to build robust, high-performance and scalable data solutions. ...

open_in_new View open_in_new SQL Server

visibility 1143
thumb_up 0
access_time 6 years ago

Serial: An Introduction to SQL Server Features Case Scenario In the previous articles of this serial, I’ve introduced how to use SQL Server as database for online transaction proces...

open_in_new View open_in_new SQL Server

visibility 4114
thumb_up 0
access_time 6 years ago

Serial: An Introduction to SQL Server Features Case Scenario For this ETL project, the requirements are listed below: Sales data will be pushed to specified shared fold...

open_in_new View open_in_new SQL Server

info About author

Kontext dark theme mode

Dark theme mode

Dark theme mode is available on Kontext.

Learn more arrow_forward
Kontext Column

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us