我们正在测试应该在1秒的基础上显示多个用户的实时数据的应用程序。 128行新的数据被插入由服务器应用每一秒到SQL datatbase然后它必须由所有用户与另一老的参照的行128沿着查询。

我们测试了该查询的时间和它不超过30个milliseonds;也调用该查询的接口功能并没有采取超过50毫秒与处理数据和所有

我们开发了创建一个线程和每每个用户的SQL连接的测试应用。用户发出7个查询每1秒。一切始于精细,并没有用户的时间超过300毫秒的7个数据系列(查询)。然而,10分钟后,等待时间超过1秒,不断增加。我们不知道,如果问题是在同一时间处理多个请求的SQL Server 2008,以及如何克服这样的问题。

下面是我们的测试客户端,如果可能的帮助。需要注意的是在客户端和服务器在同一8 CPU的机器上有8 GB RAM制造。现在,我们质疑该数据库是否可能不是我们的最佳解决方案。

   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);
        }
    }



}
有帮助吗?

解决方案

我会怀疑查询本身。虽然它可能不会采取一个空数据库上多少时间,随着数据量的增长可能会因上望起来是如何完成需要的时间越来越长。您已检查查询计划,以确保它在做索引查找,而不是表扫描来查找数据?如果不是这样,也许引进一些指标会有所帮助。

其他提示

警告:这个答案是基于MSSQL 2000的知识 - 不知道,如果它仍然是正确的。

如果你做了很多插件,该指标最终会得到过时,直到重建索引服务器将自动切换到表扫描。一些这是自动完成的,但你可能要强制定期重新索引,如果这样的性能是至关重要的。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top