複数のユーザーのリアルタイム データを 1 秒単位で表示するアプリケーションをテストしています。128 行の新しいデータがサーバー アプリケーションによって 1 秒ごとに SQL データベースに挿入され、すべてのユーザーが別の古い参照 128 行と共にクエリを実行する必要があります。
クエリ時間をテストしたところ、30 ミリ秒を超えませんでした。また、クエリを呼び出すインターフェイス関数は、データとすべての処理に 50 ミリ秒以上かかりませんでした。
各ユーザーごとにスレッドと SQL 接続を作成するテスト アプリケーションを開発しました。ユーザーは、1 秒ごとに 7 つのクエリを発行します。すべてが正常に開始され、7 つのデータ シリーズ (クエリ) に 300 ミリ秒以上かかるユーザーはいません。ただし、10 分後、レイテンシーは 1 秒を超え、増加し続けます。問題が複数の要求を同時に処理する SQL Server 2008 によるものかどうか、およびそのような問題を克服する方法はわかりません。
役立つかどうかをテストするクライアントを次に示します。クライアントとサーバーは、8 GB RAM を搭載した同じ 8 CPU マシンで作成されていることに注意してください。現在、データベースが私たちにとって最適なソリューションではないかどうか疑問に思っています。
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Number of threads");
int threads = int.Parse(Console.ReadLine());
ArrayList l = new ArrayList();
for (int i = 0; i < threads; i++)
{
User u = new User();
Thread th = new Thread(u.Start);
th.IsBackground = true;
th.Start();
l.Add(u);
l.Add(th);
}
Thread.CurrentThread.Join();
GC.KeepAlive(l);
}
}
class User
{
BusinessServer client ; // the data base interface dll
public static int usernumber =0 ;
static TextWriter log;
public User()
{
client = new BusinessServer(); // creates an SQL connection in the constructor
Interlocked.Increment(ref usernumber);
}
public static void SetLog(int processnumber)
{
log = TextWriter.Synchronized(new StreamWriter(processnumber + ".txt"));
}
public void Start()
{
Dictionary<short, symbolStruct> companiesdic = client.getSymbolData();
short [] symbolids=companiesdic.Keys.ToArray();
Stopwatch sw = new Stopwatch();
while (true)
{
int current;
sw.Start();
current = client.getMaxCurrentBarTime();
for (int j = 0; j < 7; j++)
{
client.getValueAverage(dataType.mv, symbolids,
action.Add, actionType.Buy,
calculationType.type1,
weightType.freeFloatingShares, null, 10, current, functionBehaviour.difference); // this is the function that has the queries
}
sw.Stop();
Console.WriteLine(DateTime.Now.ToString("hh:mm:ss") + "\t" + sw.ElapsedMilliseconds);
if (sw.ElapsedMilliseconds > 1000)
{
Console.WriteLine("warning");
}
sw.Reset();
long diff = 0;//(1000 - sw.ElapsedMilliseconds);
long sleep = diff > 0 ? diff : 1000;
Thread.Sleep((int)sleep);
}
}
}