我正在運行一個測試,比較獲取時間b/w appfabric和SQL Server 2008,並且看起來appFabric比SQL Server執行速度慢4倍。Appfabric Cache比SQL Server 2008執行速度慢4倍?
我有一個SQL Server 2008安裝程序,它只包含一個包含4列的表(全部爲nvarchar
)。該表有6000行。我在appfabric緩存中插入相同的行(如CLR可序列化的obj)。我正在運行一個循環來獲取數據x次。
下面是代碼
public class AppFabricCache
{
readonly DataCache myDefaultCache;
public AppFabricCache()
{
//-------------------------
// Configure Cache Client
//-------------------------
//Define Array for 1 Cache Host
var servers = new List<DataCacheServerEndpoint>(1);
//Specify Cache Host Details
// Parameter 1 = host name
// Parameter 2 = cache port number
servers.Add(new DataCacheServerEndpoint(@"localhost", 22233));
//Create cache configuration
var configuration = new DataCacheFactoryConfiguration();
//Set the cache host(s)
configuration.Servers = servers;
//Set default properties for local cache (local cache disabled)
configuration.LocalCacheProperties = new DataCacheLocalCacheProperties();
//Disable exception messages since this sample works on a cache aside
DataCacheClientLogManager.ChangeLogLevel(System.Diagnostics.TraceLevel.Off);
//Pass configuration settings to cacheFactory constructor
DataCacheFactory myCacheFactory = new DataCacheFactory(configuration);
//Get reference to named cache called "default"
myDefaultCache = myCacheFactory.GetCache("default");
}
public bool TryGetCachedObject(string key, out object value)
{
value = myDefaultCache.Get(key);
bool result = value != null;
return result;
}
public void PutItemIntoCache(string key, object value)
{
myDefaultCache.Put(key, value, TimeSpan.FromDays(365));
}
}
,這裏是循環從緩存
public double RunReadStressTest(int numberOfIterations, out int recordReadCount)
{
recordReadCount = 0;
Stopwatch sw = Stopwatch.StartNew();
for (int i = 0; i < numberOfIterations; i++)
{
for (int j = 1; j <= 6000; j++)
{
string posId = "PosId-" + j;
try
{
object value;
if (TryGetCachedObject(posId, out value))
recordReadCount++;
}
catch (Exception e)
{
Trace.WriteLine("AS%% - Exception - " + e.Message);
}
}
}
sw.Stop();
return sw.ElapsedMilliseconds;
}
}
獲取數據我有完全一樣的邏輯從SQL Server檢索數據。它創建了一個
sqlCommand = 'Select * from TableName where posId = 'someId''
下面是結果...
SQL Server 2008 R2 Reading-1(ms) Reading-2(ms) Reading-3(ms) Average Time in Seconds
Iteration Count = 5 2528 2649 2665 2.614
Iteration Count = 10 5280 5445 5343 5.356
Iteration Count = 15 7978 8370 7800 8.049333333
Iteration Count = 20 9277 9643 10220 9.713333333
AppFabric Reading-1 Reading-2 Reading-3 Average Time in Seconds
Iteration Count = 5 10301 10160 10186 10.21566667
Iteration Count = 10 20130 20191 20650 20.32366667
Iteration Count = 15 30747 30571 30647 30.655
Iteration Count = 20 40448 40541 40503 40.49733333
我失去了一些東西在這裏?爲什麼這麼慢?
我不認爲你之前使用過d-cache。只知道一些東西是不夠的。 >>如果我啓用本地緩存,那將是一個不公平的測試。 >>散裝得到 - 我可以做同樣的SQL服務器以及我敢肯定,這將是顯着快。 Sql Server只不過是檢索一行而已。 >>爲什麼我要啓用壓縮只有6K記錄。每個只有4個字符串存儲。 – user1707312
@ user1707312我不明白你的意見。你能解釋一下嗎?我不是AppFabric的主人。我從一年以後就使用了它。如果您以前使用過d-cache,那麼您應該也知道使用d-cache並不是爲了提高性能,而是提高可伸縮性。使用單個數據表的單個客戶端的for循環中的「加載測試」不是最好的方法。 – Cybermaxs
忘記 - 讓我們不要進入它。從性能角度考慮,AppFabric與Memcache/Couchbase進行比較。 – user1707312