1

EF/Autofac と memcached (3 つのフロント エンド サーバー) を使用する MVC3 アプリがあります。アプリを起動すると、1 ユーザーで 300MB まですばやくジャンプします。私たちの実稼働サイト (トラフィックが少ない (一度に 10 人未満のユーザー)) では、1.2 GB を超えるメモリに簡単に到達できます。これは私には非常に大きな数のように思えます。

Redgate Memory Profiler を試してみましたが、異常に見えるものを見つけることができないようです。

私が考えることができる唯一のことは、おそらく次のコードが何らかのメモリリークを引き起こしているということです。どう思いますか?

private Dictionary<string, object> cacheDictionary = new Dictionary<string, object>();

    private IMemcachedClient _client;

    public MemcachedManager(IMemcachedClient client)
    {
        this._client = client;
    }

    #region ICacheManager Members

    public T Get<T>(string key)
    {
        object data;
        if (!cacheDictionary.TryGetValue(key, out data))
        {
            byte[] byteData = _client.Get<byte[]>(key);
            data = CommonHelper.Deserialize<T>(byteData);
            cacheDictionary.Add(key, data);
        }
        return (T)data;
    }

    public void Set(string key, object data, int cacheTime)
    {
        if (!cacheDictionary.ContainsKey(key)) //if memcache turned off this should still work
            cacheDictionary.Add(key, data);

        data = CommonHelper.Serialize(data);
        bool setCache = _client.Store(StoreMode.Set, key, data, DateTime.Now.AddMinutes(cacheTime));

        if (!setCache)
        {
            log.ErrorFormat("Failed to set the cache item, key {0}", key);
        }
    }
4

0 に答える 0