Unity-Technologies / com.unity.netcode.gameobjects

Netcode for GameObjects is a high-level netcode SDK that provides networking capabilities to GameObject/MonoBehaviour workflows within Unity and sits on top of underlying transport layer.
MIT License
2.14k stars 433 forks source link

Metrics Dispatch Warning Log #2297

Open CosmicStud opened 1 year ago

CosmicStud commented 1 year ago

Description

In the package "Multiplayer Tools", The "MeticDispatcher" class, "Dispatch" method spams a warning of metrics over the limit, it tends to lower fps when viewing console on builds, and makes dev logging much more difficult

Reproduce Steps

Send network messages in abundance

Actual Outcome

Messages are sent and received successfully, though there are spammed logs every frame

Expected Outcome

Maybe a few logs to alert of the limits of the profiler, not spammed

Environment

CosmicStud commented 1 year ago

I added the package from the disk, added a small counter, if its more then my max, it wont print, it resets the log count if not over the limit

`internal MetricDispatcher(MetricCollection collection, IReadOnlyList resettables, IReadOnlyList eventMetrics) { m_Collection = collection; m_Resettables = resettables; m_EventMetrics = eventMetrics; }

    public void RegisterObserver(IMetricObserver observer)
    {
        m_Observers.Add(observer);
    }

    public void SetConnectionId(ulong connectionId)
    {
        m_Collection.ConnectionId = connectionId;
    }

    private int logCount = 0;
    public void Dispatch()
    {
        var wentOverLimit = false;
        for (var i = 0; i < m_EventMetrics.Count; i++)
        {
            if (m_EventMetrics[i].WentOverLimit)
            {
                wentOverLimit = true;
                break;
            }
        }

        //Added custom code to increment and check log count
        if (wentOverLimit && logCount < 1)
        {
            logCount += 1;
            Debug.LogWarning(k_ThrottlingWarning);
        }

        //Added custom code to reset log counter
        else
        {
            logCount = 0;
        }

        for (var i = 0; i < m_Observers.Count; i++)
        {
            var snapshotObserver = m_Observers[i];
            snapshotObserver.Observe(m_Collection);
        }

        for (var i = 0; i < m_Resettables.Count; i++)
        {
            var resettable = m_Resettables[i];
            if (resettable.ShouldResetOnDispatch)
            {
                resettable.Reset();
            }
        }
    }`
CosmicStud commented 1 year ago

//Changed log count due to my needs and a lot of spam `public void Dispatch() { var wentOverLimit = false; for (var i = 0; i < m_EventMetrics.Count; i++) { if (m_EventMetrics[i].WentOverLimit) { wentOverLimit = true; break; } }

        if (wentOverLimit)
        {
            logCount += 1;

            if (logCount == 200)
            {
                logCount = 0;
                Debug.LogWarning(k_ThrottlingWarning);
            }
        }

        for (var i = 0; i < m_Observers.Count; i++)
        {
            var snapshotObserver = m_Observers[i];
            snapshotObserver.Observe(m_Collection);
        }

        for (var i = 0; i < m_Resettables.Count; i++)
        {
            var resettable = m_Resettables[i];
            if (resettable.ShouldResetOnDispatch)
            {
                resettable.Reset();
            }
        }
    }`
ashwinimurt commented 1 year ago

Duplicate of https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/issues/2058 MTT-3388

CosmicStud commented 1 year ago

Okay, did not notice that.

There is another log, although not spammed as much. If a custom build is completed it'll send more than a few of these Runtime Net Stats Monitor (RNSM) implementation disabled in release build targeting StandaloneLinux64

The log is located in the package "Unity.Multiplayer.Tools", class "NetStatsMonitorBuildLogEntry", "OnPostprocessBuild" method

mtarzwell commented 1 year ago

Hello @CosmicStud in November our team did some work to improve metric throttling. It would have shipped out with our Tools 1.1.0 release. Can you confirm if you're still seeing it along with that version? Thank you.