Limited throughput on high repetition rate using TCP/IP connection using Instrument Control Toolbox
4 次查看(过去 30 天)
显示 更早的评论
I have embedded hardware that we developed in house that acquires data at rates of up to 5 kHz and streams this data (at throughput levels of 100+ Mbps). It is a simple TCP protocol that includes a defined header (specifiying the payload size) followed by the payload. I am able to succesfully consume this data stream in other languages (Python, LabVIEW, C##, etc.). However I am having difficutly creating an API in MATLAB that can keep up.
To simplify I have created a client and server scripts in MATLAB to test the TCP implmenetation in MATLAB (shown below, start server first, then start client).
The data throughput is very low here (only a few bytes per TCP read/write). However, the server can't send data much faster than 1500 Hz and the client can barely keep up at 1 kHz. Note I am running MATLAB on a Mac. Similar performance on a Windows 10 machine.
Am I missing something in the configuration? In other languages, I can do this well above 5 kHz withouth a problem.
Here is the server:
clc
clear all
instrreset
number_of_packets = 10000;
instrument_server = tcpip('0.0.0.0', 51971, 'NetworkRole', 'server');
fopen(instrument_server);
tic
for k1 = 1:number_of_packets
if mod(k1, 100) == 0
sprintf('Sending %d . . .', k1)
end
message = sprintf('Sending %d', k1);
fwrite(instrument_server, uint8(length(message)));
fwrite(instrument_server, uint8(message));
end
et = toc;
sprintf('Average data rate = %f Hz', 1/(et/number_of_packets))
fclose(instrument_server);
Here is the client:
clc
clear all
instrreset
number_of_packets = 10000;
instrument_client = tcpip('localhost', 51971, 'timeout', 1);
fopen(instrument_client);
tic
for k1 = 1:number_of_packets
if mod(k1, 100) == 0
sprintf('Reading %d . . .', k1)
end
message_length = fread(instrument_client, 1);
message = fread(instrument_client, message_length);
end
et = toc;
sprintf('Average data rate = %f Hz', 1/(et/number_of_packets))
fclose(instrument_client);
3 个评论
Walter Roberson
2019-5-17
You are right, on my Mac, setting input and output buffer sizes to fairly large did not make any notable difference.
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Instrument Control Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!