Skip to content

Commit 7fec1b3

Browse files
author
Sergey
committed
Fix work with LiteDB
1 parent b8aa00d commit 7fec1b3

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

JMeterTests/!run_stressTest_poll_couters.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
SET PRJ_PATH=%CD%
33

4-
"c:\Program Files (x86)\JMeter\bin\jmeter" -e -n -t %PRJ_PATH%\StressTest_PollCounters_TestService.jmx -l %PRJ_PATH%\StressTest_PollCounters_TestService_res.jtl
4+
"c:\Program Files (x86)\JMeter\bin\jmeter" -e -n -t %PRJ_PATH%\StressTest_PollCounters_TestService.jmx -l %PRJ_PATH%\StressTest_PollCounters_TestService_res2.jtl
55

66
rem -l %PRJ_PATH%\test.jtl
77

Perfon.Core/PerfCounterStorages/PerfCounterLiteDbStorage.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public Task StorePerfCounters(IEnumerable<IPerfCounterData> counters)
4343

4444
var dbName = GetDbName(now);
4545

46-
using (var db = new LiteDatabase(PathToDbFolder + dbName))
46+
using (var db = new LiteDatabase(dbName))
4747
{
4848
using (var trans = db.BeginTrans())
4949
{
@@ -105,13 +105,13 @@ public Task<IEnumerable<PerfCounterValue>> QueryCounterValues(string counterName
105105
{
106106
using (var db = new LiteDatabase(GetDbReadOnlyName(date.Value)))
107107
{
108-
list = db.Engine.Find(counterName.GetHashCode().ToString(), Query.GTE("Timestamp", new BsonValue(date)), skip).Select(a =>
109-
{
110-
return new PerfCounterValue(a["Timestamp"].AsDateTime, (float)a["Value"].AsDouble);
111-
}).ToList();
108+
//list = db.Engine.Find(counterName.GetHashCode().ToString(), Query.GTE("Timestamp", new BsonValue(date)), skip).Select(a =>
109+
// {
110+
// return new PerfCounterValue(a["Timestamp"].AsDateTime, (float)a["Value"].AsDouble);
111+
// }).ToList();
112112

113-
//var countersColl = db.GetCollection<PerfCounterValue>(counterName.GetHashCode().ToString());
114-
//list = countersColl.FindAll().Where(a => a.Timestamp.Date == date).ToList();
113+
var countersColl = db.GetCollection<PerfCounterValue>(counterName.GetHashCode().ToString());
114+
list = countersColl.FindAll().Where(a => a.Timestamp.Date == date).ToList();
115115
}
116116
}
117117
catch (Exception exc)
@@ -133,14 +133,12 @@ public Task<IEnumerable<string>> GetCountersList()
133133
{
134134
var now = DateTime.Now;
135135

136-
var dbName = GetDbName(now);
137-
138-
using (var db = new LiteDatabase(PathToDbFolder + dbName))
136+
using (var db = new LiteDatabase(GetDbReadOnlyName(now)))
139137
{
140-
//var names = db.GetCollection("CounterNames");
141-
//res = names.FindAll().Select(a => a["Name"].AsString).ToList();
138+
var names = db.GetCollection("CounterNames");
139+
res = names.FindAll().Select(a => a["Name"].AsString).ToList();
142140

143-
res = db.Engine.FindAll("CounterNames").Select(a => a["Name"].AsString).ToList();
141+
//res = db.Engine.FindAll("CounterNames").Select(a => a["Name"].AsString).ToList();
144142
}
145143
}
146144
catch (Exception exc)
@@ -158,13 +156,21 @@ public Task<IEnumerable<string>> GetCountersList()
158156

159157

160158

161-
private static string GetDbName(DateTime now)
159+
private string GetDbName(DateTime now)
162160
{
163-
return "perfCounters_" + now.ToString("yyyy-MM-dd") + ".litedb";
161+
return PathToDbFolder + "perfCounters_" + now.ToString("yyyy-MM-dd") + ".litedb";
164162
}
165163
private string GetDbReadOnlyName(DateTime date)
166164
{
167-
return "Filename=" + PathToDbFolder + GetDbName(date) + ";Mode=ReadOnly;Timeout=" + TimeSpan.FromSeconds(30);
165+
//return GetDbName(date);
166+
167+
string journal = "";
168+
if (date.Date != DateTime.Now.Date)
169+
{
170+
journal = ";Journal=false";
171+
}
172+
//;Mode=ReadOnly
173+
return "Filename=" + GetDbName(date) + journal + ";Mode=ReadOnly";//;Timeout=" + TimeSpan.FromSeconds(30);
168174
}
169175

170176

Perfon.WebApi/Controllers/PerfCountersController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task<IHttpActionResult> Get([FromUri]string name, [FromUri]DateTime
6868
string key = name + date.GetHashCode();
6969
var res = MemoryCache.Default.Get(key) as IEnumerable<PerfCounterValue>;
7070

71-
if (res == null)
71+
if (res == null || res.Count() <= 0)
7272
{
7373
// Not the best solution. Use Lazy here??
7474
res = await Db.QueryCounterValues(name, date);

0 commit comments

Comments
 (0)