# QueueSize

Last Modified: February 7, 2020

For output sessions, queues store data passed to XNET Write and not yet transmitted onto the network. For input sessions, queues store data received from the network and not yet obtained using XNET Read. For most applications, the default queue sizes are sufficient. You can write to this property to override the default.

When you write (set) this property, you must do so prior to the first session start. You cannot set this property again after calling XNET Stop.

For signal I/O sessions, this property is the number of signal values stored. This is analogous to the number of values you use with XNET Read or XNET Write.

For frame I/O sessions, Queue Size is the number of bytes of frame data stored.

For standard CAN and LIN frame I/O sessions, each frame uses exactly 24 bytes. You can use this number to convert the Queue Size (in bytes) to/from the number of frame values.

For CAN FD and FlexRay frame I/O sessions, each frame value size can vary depending on the payload length. For more information, refer to Raw Frame Format.

For Signal I/O XY sessions, you can use signals from more than one frame. Within the implementation, each frame uses a dedicated queue. According to the formulas below, the default queue sizes can be different for each frame. If you read the default Queue Size property for a Signal Input XY session, the largest queue size is returned, so that a call to XNET Read of that size can empty all queues. If you read the default Queue Size property for a Signal Output XY session, the smallest queue size is returned, so that a call to XNET Write of that size can succeed when all queues are empty. If you write the Queue Size property for a Signal I/O XY session, that size is used for all frames, so you must ensure that it is sufficient for the frame with the fastest transmit time.

For Signal I/O Waveform sessions, you can use signals from more than one frame. Within the implementation, each frame uses a dedicated queue. The Queue Size property does not represent the memory in these queues, but rather the amount of time stored. The default queue allocations store Application Time worth of resampled signal values. If you read the default Queue Size property for a Signal I/O Waveform session, it returns Application Time multiplied by the time Resample Rate. If you write the Queue Size property for a Signal I/O Waveform session, that value is translated from a number of samples to a time, and that time is used to allocate memory for each queue.

For Single-Point sessions (signal or frame), this property is ignored. Single-Point sessions always use a value of 1 as the effective queue size.

Data type:

Long Name: Queue Size

Class: XNET Session

Permissions: Read/Write

## Default Value

You calculate the default queue size based on the following assumptions:

• Application Time: The time between calls to the XNET Read VI/XNET Write VI in your application.
• Frame Time: The time between frames on the network for this session.

The following pseudo code describes the default queue size formula:

if (session is Signal I/O Waveform)              Queue_Size = (Application_Time * Resample_Rate);           else              Queue_Size = (Application_Time / Frame_Time);           if (Queue_Size < 64)              Queue_Size = 64;           if (session mode is Frame I/O)              Queue_Size = Queue_Size * Frame_Size;

For Signal I/O Waveform sessions, the initial formula calculates the number of resampled values that occur within the Application Time. This is done by multiplying Application Time by the XNET Session Resample Rate property.

For all other session modes, the initial formula divides Application Time by Frame Time.

The minimum for this formula is 64. This minimum ensures that you can read or write at least 64 elements. If you need to read or write more elements for a slow frame, you can set the Queue Size property to a larger number than the default. If you set a large Queue Size, this may limit the maximum number of frames you can use in all sessions.

For Frame I/O sessions, this formula result is multiplied by each frame value size to obtain a queue size in bytes.

For Signal I/O sessions, this formula result is used directly for the queue size property to provide the number of signal values for the XNET Read VI or XNET Write VI. Within the Signal I/O session, the memory allocated for the queue incorporates frame sizes, because the signal values are mapped to/from frame values internally.

## Application Time

The LabVIEW target in which your application runs determines the Application Time:

• Windows: 400 ms (0.4 s)
• LabVIEW Real-Time (RT): 100 ms (0.1 s)

This works under the assumption that for Windows, more memory is available for input queues, and you have limited control over the application timing. LabVIEW RT targets typically have less available memory, but your application has better control over application timing.

## Frame Time

Frame Time is calculated differently for Frame I/O Stream sessions compared to other modes. For Frame I/O Stream, you access all frames in the network (cluster), so the Frame Time is related to the average bus load on your network. For other modes, you access specific frames only, so the Frame Time is obtained from database properties for those frames.

The Frame Time used for the default varies by session mode and protocol, as described below.

CAN, Frame I/O Stream:

• Frame Time is 100 µs (0.0001 s). This time assumes a baud rate of 1 Mbps, with frames back to back (100 percent busload).
• For CAN sessions created for a standard CAN bus, the Frame Size is 24 bytes. For CAN sessions created for a CAN FD Bus (the cluster I/O mode is CAN FD or CAN FD+BRS), the frame size can vary up to 64 bytes. However, the default queue size is based on the 24-byte frame time. When connecting to a CAN FD bus, you may need to adjust this size as necessary.
• When you create an application to stress test NI-XNET performance, it is possible to generate CAN frames faster than 100 µs. For this application, you must set the queue size to larger than the default.

FlexRay, Frame I/O Stream:

• Frame Time is 20 µs (0.00002 s). This time assumes a baud rate of 10 Mbps, with a cycle containing static slots only (no minislots or NIT), and frames on channel A only.
• Small frames at a fast rate require a larger queue size than large frames at a slow rate. Therefore, this default assumes static slots with 4 bytes, for a Frame Size of 24 bytes.
• When you create an application to stress test NI-XNET performance, it is possible to generate FlexRay frames faster than 20 µs. For this application, you must set the queue size to larger than the default.

LIN, Frame I/O Stream:

• Frame Time is 2 ms (0.002 s). This time assumes a baud rate of 20 kbps, with 1 byte frames back to back (100 percent busload).
• For all LIN sessions, Frame Size is 24 bytes.

CAN, Other Modes:

• For Frame I/O Queued, Signal I/O XY, and Signal I/O Waveform, the Frame Time is different for each frame in the session (or frame within which signals are contained).
• For CAN frames, Frame Time is the frame property CAN Transmit Time, which specifies the time between successive frames (in floating-point seconds).
• If the frame's CAN Transmit Time is 0, this implies the possibility of back-to-back frames on the network. Nevertheless, this back-to-back traffic typically occurs in bursts, and the average rate over a long period of time is relatively slow. To keep the default queue size to a reasonable value, when CAN Transmit Time is 0, the formula uses a Frame Time of 50 ms (0.05 s).
• For CAN sessions using a standard CAN cluster, the frame size is 24 bytes. For CAN sessions using a CAN FD cluster, the frame size may differ for each frame in the session. Each frame size is obtained from its XNET Frame Payload Length property in the database.

FlexRay, Other Modes:

• For Frame I/O Queued, Signal I/O XY, and Signal I/O Waveform, the Frame Time is different for each frame in the session (or frame within which signals are contained).
• For FlexRay frames, Frame Time is the time between successive frames (in floating-point seconds), calculated from cluster and frame properties. For example, if a cluster Cycle (cycle duration) is 10000 µs, and the frame Base Cycle is 0 and Cycle Repetition is 1, the frame's Transmit Time is 0.01 (10 ms).
• For these session modes, the Frame Size is different for each frame in the session. Each Frame Size is obtained from its XNET Frame Payload Length property in the database.

LIN, Other Modes:

• For LIN frames, Frame Time is a property of the schedule running in the LIN master node. It is assumed that the Frame Time for a single frame always is larger than 8 ms, so that the default queue size is set to 64 frames throughout.
• For all LIN sessions, Frame Size is 24 bytes.

## Examples

The following table lists example session configurations and the resulting default queue sizes.

Session Configuration Default Queue Size Formula
Frame Input Stream, CAN, Windows 96000 (0.4 / 0.0001) = 4000; 4000 x 24 bytes
Frame Output Stream, CAN, Windows 96000 (0.4 / 0.0001) = 4000; 4000 x 24 bytes; output is always same as input
Frame Input Stream, FlexRay, Windows 480000 (0.4 / 0.00002) = 20000; 20000 x 24 bytes
Frame Input Stream, CAN, LabVIEW RT 24000 (0.1 / 0.0001) = 1000; 1000 x 24 bytes
Frame Input Stream, FlexRay, LabVIEW RT 120000 (0.1 / 0.00002) = 5000; 5000 x 24 bytes
Frame Input Queued, CAN, Transmit Time 0.0, Windows 1536 [1] (0.4 / 0.05) = 8; Transmit Time 0 uses Frame Time 50 ms; use minimum of 64 frames (64 x 24)
Frame Input Queued, CAN, Transmit Time 0.0005, Windows 19200 [1] (0.4 / 0.0005) = 800; 800 x 24 bytes
Frame Input Queued, CAN, Transmit Time 1.0 (1 s), Windows 1536 [1] (0.4 / 1.0) = 0.4; use minimum of 64 frames (64 x 24)
Frame Input Queued, FlexRay, every 2 ms cycle, payload length 4, Windows 4800 (0.4 / 0.002) = 200; 200 x 24 bytes
Frame Input Queued, FlexRay, every 2 ms cycle, payload length 16, LabVIEW RT 2048 (0.1 / 0.002) = 50, use minimum of 64; payload length 16 requires 32 bytes; 64 x 32 bytes
Signal Input XY, two CAN frames, Transmit Time 0.0 and 0.0005, Windows 64 [1] and 800 [1] (read as 800) (0.4 / 0.05) = 8, use minimum of 64; (0.4 / 0.0005) = 800; expressed as signal values
Signal Output XY, two CAN frames, Transmit Time 0.0 and 0.0005, Windows 64 [1] and 800 [1] (read as 64) (0.4 / 0.05) = 8, use minimum of 64; (0.4 / 0.0005) = 800; expressed as signal values
Signal Output Waveform, two CAN frames, 1 ms and 400 ms, resample rate 1000 Hz, Windows 400 [1] Memory allocation is 400 and 64 frames to provide 0.4 sec of storage, queue size represents number of samples, or (0.4 x 1000.0)

Where This Property Is Available:

Desktop OS: Windows

FPGA: Not supported

Web Server: Not supported in VIs that run in a web application

• 1 For a CAN FD cluster, the default queue size is based on the frame's database payload length, which may be larger than 24 bytes (up to 64 bytes).