Skip to content

fix: Rename 'Send Queue Batch Size' field in adapter #1584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.netcode.adapter.utp/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to this package will be documented in this file. The format

### Changed

- Rename the 'Send Queue Batch Size' property to 'Max Payload Size' to better reflect its usage (#1584)

### Fixed

## [1.0.0-pre.4] - 2022-01-04
Expand Down
21 changes: 11 additions & 10 deletions com.unity.netcode.adapter.utp/Runtime/UnityTransport.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using NetcodeNetworkEvent = Unity.Netcode.NetworkEvent;
using TransportNetworkEvent = Unity.Networking.Transport.NetworkEvent;
using Unity.Collections.LowLevel.Unsafe;
Expand Down Expand Up @@ -85,8 +86,8 @@ private enum State
}

public const int InitialMaxPacketQueueSize = 128;
public const int InitialBatchQueueSize = 6 * 1024;
public const int InitialMaxSendQueueSize = 16 * InitialBatchQueueSize;
public const int InitialMaxPayloadSize = 6 * 1024;
public const int InitialMaxSendQueueSize = 16 * InitialMaxPayloadSize;

private static ConnectionAddressData s_DefaultConnectionAddressData = new ConnectionAddressData()
{ Address = "127.0.0.1", Port = 7777 };
Expand All @@ -103,9 +104,9 @@ private enum State
"Basically this is how many packets can be sent/received in a single update/frame.")]
[SerializeField] private int m_MaxPacketQueueSize = InitialMaxPacketQueueSize;

[Tooltip("The maximum size of a batched send. The send queue accumulates messages and batches them together " +
"up to this size. This is effectively the maximum payload size that can be handled by the transport.")]
[SerializeField] private int m_SendQueueBatchSize = InitialBatchQueueSize;
[Tooltip("The maximum size of a payload that can be handled by the transport.")]
[FormerlySerializedAs("m_SendQueueBatchSize")]
[SerializeField] private int m_MaxPayloadSize = InitialMaxPayloadSize;

[Tooltip("The maximum size in bytes of the transport send queue. The send queue accumulates messages for " +
"batching and stores messages when other internal send queues are full. If you routinely observe an " +
Expand Down Expand Up @@ -639,9 +640,9 @@ public override void Initialize()

m_NetworkSettings = new NetworkSettings(Allocator.Persistent);

// If the user sends a message of exactly m_SendQueueBatchSize in length, we need to
// If the user sends a message of exactly m_MaxPayloadSize in length, we need to
// account for the overhead of its length when we store it in the send queue.
var fragmentationCapacity = m_SendQueueBatchSize + BatchedSendQueue.PerMessageOverhead;
var fragmentationCapacity = m_MaxPayloadSize + BatchedSendQueue.PerMessageOverhead;

m_NetworkSettings
.WithFragmentationStageParameters(payloadCapacity: fragmentationCapacity)
Expand All @@ -660,9 +661,9 @@ public override NetcodeNetworkEvent PollEvent(out ulong clientId, out ArraySegme

public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDelivery networkDelivery)
{
if (payload.Count > m_SendQueueBatchSize)
if (payload.Count > m_MaxPayloadSize)
{
Debug.LogError($"Payload of size {payload.Count} larger than configured 'Send Queue Batch Size' ({m_SendQueueBatchSize}).");
Debug.LogError($"Payload of size {payload.Count} larger than configured 'Max Payload Size' ({m_MaxPayloadSize}).");
return;
}

Expand All @@ -671,7 +672,7 @@ public override void Send(ulong clientId, ArraySegment<byte> payload, NetworkDel
var sendTarget = new SendTarget(clientId, pipeline);
if (!m_SendQueue.TryGetValue(sendTarget, out var queue))
{
queue = new BatchedSendQueue(Math.Max(m_MaxSendQueueSize, m_SendQueueBatchSize));
queue = new BatchedSendQueue(Math.Max(m_MaxSendQueueSize, m_MaxPayloadSize));
m_SendQueue.Add(sendTarget, queue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DriverClient : MonoBehaviour
private void Awake()
{

var maxCap = UnityTransport.InitialBatchQueueSize + 128;
var maxCap = UnityTransport.InitialMaxPayloadSize + 128;

var settings = new NetworkSettings();
settings.WithFragmentationStageParameters(payloadCapacity: maxCap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public IEnumerator SendMaximumPayloadSize([ValueSource("k_DeliveryParameters")]

yield return WaitForNetworkEvent(NetworkEvent.Connect, m_Client1Events);

var payload = new ArraySegment<byte>(new byte[UnityTransport.InitialBatchQueueSize]);
var payload = new ArraySegment<byte>(new byte[UnityTransport.InitialMaxPayloadSize]);
m_Client1.Send(m_Client1.ServerClientId, payload, delivery);

yield return WaitForNetworkEvent(NetworkEvent.Data, m_ServerEvents);
Expand Down Expand Up @@ -171,7 +171,7 @@ public IEnumerator FilledSendQueueMultipleSends([ValueSource("k_DeliveryParamete
yield return new WaitForSeconds(numSends * 0.02f);

// Extra event is the connect event.
Assert.AreEqual(m_ServerEvents.Count, numSends + 1);
Assert.AreEqual(numSends + 1, m_ServerEvents.Count);

for (int i = 1; i <= numSends; i++)
{
Expand Down