Code Monkey home page Code Monkey logo

Comments (9)

DannyRichardsonWG avatar DannyRichardsonWG commented on June 12, 2024 1

I'm not sure but It looks like GetInfoMessages is firing multiple times for the same connection/query so the elapsed/cpu times are counted more than once (so two messages with 2000 in one and 3000 in the later one = 5000 for that single query). You should be able to replicate by putting a breakpoint on the parsing code and running a test with 1 iteration and 1 thread

Proposed fix:

Track times by connection client ID in a dictionary so the value is only counted once. Then after each query completes allocate that to a global counter.

GetInfoMessages

` //we have times
if (matches.Length > 1)
{
var conn = (SqlConnection)sender;
var id = conn.ClientConnectionId;

                    //could probably add this to the connection creation area to tidy it up
                    if (!_outInfo.CpuTimes.TryGetValue(id, out var _))
                    {
                        _outInfo.CpuTimes.Add(conn.ClientConnectionId, 0);
                        _outInfo.ElapsedTimes.Add(conn.ClientConnectionId, 0);
                    }
                    //set the values for this connection to the last known amount
                    _outInfo.CpuTimes[id] = Convert.ToDouble(matches[1], CultureInfo.InvariantCulture);
                    _outInfo.ElapsedTimes[id] = Convert.ToDouble(matches[2], CultureInfo.InvariantCulture);

                    //_outInfo.CpuTime += Convert.ToInt32(matches[1], CultureInfo.InvariantCulture);
                    //_outInfo.ElapsedTime += Convert.ToInt32(matches[2], CultureInfo.InvariantCulture);
                }`

And then QueryOutput updates

` public class QueryOutput
{
public double CpuTime => trackedCpu + CpuTimes.Values.Sum();
public Exception E;
public double ElapsedTime => trackedElapsedTime + ElapsedTimes.Values.Sum();
public bool Finished;
public int LogicalReads;
public TimeSpan Time;

        public ConcurrentDictionary<Guid, double> CpuTimes = new();
        public ConcurrentDictionary<Guid, double> ElapsedTimes = new();

        private double trackedCpu = 0;
        private double trackedElapsedTime = 0;
        private object updateLock = new();


        public void ClearTimes(Guid clientId)
        {
            lock (updateLock)
            {
                if (CpuTimes.TryGetValue(clientId, out double cpu))
                    CpuTimes[clientId] = 0;
                if (ElapsedTimes.TryGetValue(clientId, out double elapsed))
                    ElapsedTimes[clientId] = 0;

                trackedCpu += cpu;
                trackedElapsedTime += elapsed;
            }
        }

...
`

And clear after each query:

//set up the statistics gathering if (_statsComm != null) { _statsComm.ExecuteNonQuery(); Thread.Sleep(0); _outInfo.ClearTimes(conn.ClientConnectionId); }

With these changes my results look more consistent.

I only saw the tool today so I'm not very familiar with it so if that explanation makes sense to you and you can duplicate the multi-message I'm happy to put a PR in with the changes next week when I get some time to tidy it up.

from sqlquerystress.

buckleyGI avatar buckleyGI commented on June 12, 2024

I also set the setting to true so that all the results are streamed to the client in the 2nd screenshot.
Although I think that isn't relevant give that all the numbers are about the same.

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

This is part if the original implementation, and not something I have touched the last 15 years. Maybe there is some info in the wiki?

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

Any updates?

from sqlquerystress.

buckleyGI avatar buckleyGI commented on June 12, 2024

Ideally the metrics displayed are accompanied by an explanation.
I favor a question mark that shows what it conveys when you have over it. This will be some work that I currently don't have the cycles for.
AFAIK there is no documentation that is reachable from the GUI. That would be a place for it as well.

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

Does this help? https://github.com/ErikEJ/SqlQueryStress/wiki

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

@DannyRichardsonWG Feel free to create a PR!

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

@DannyRichardsonWG Any plans to submit a PR?

from sqlquerystress.

ErikEJ avatar ErikEJ commented on June 12, 2024

@DannyRichardsonWG I am not able to reproduce the duplicate message events

from sqlquerystress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.