1

我们正在测试一个应用程序,该应用程序应该在 1 秒内为多个用户显示实时数据。服务器应用程序每秒将 128 行的新数据插入 SQL 数据库,然后所有用户必须查询它以及另一个旧的参考 128 行。

我们测试了查询时间,没有超过 30 毫秒;调用查询的接口函数处理数据的时间也不超过 50 毫秒,所有

我们开发了一个测试应用程序,它为每个用户创建一个线程和一个 SQL 连接。用户每 1 秒发出 7 个查询。一切都很好,没有用户花费超过 300 毫秒的 7 个数据系列(查询)。但是,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);
        }
    }



}
4

2 回答 2

1

Warning: this answer is based on knowledge of MSSQL 2000 - not sure if it is still correct.

If you do a lot of inserts, the indexes will eventually get out of date and the server will automatically switch to table scans until the indexes are rebuilt. Some of this is done automatically, but you may want to force reindexing periodically if this kind of performance is critical.

于 2009-05-16T16:46:27.997 回答
0

I would suspect the query itself. While it may not take much time on an empty database, as the amount of data grows it may require more and more time depending on how the look up is done. Have you examined the query plan to make sure that it is doing index lookups instead of table scans to find the data? If not, perhaps introducing some indexes would help.

于 2009-05-16T14:31:22.063 回答