Effacer les filtres
Effacer les filtres

udpport write very slow, how to speed it up?

12 vues (au cours des 30 derniers jours)
Chris Wolf
Chris Wolf le 23 Mai 2024
Réponse apportée : Poorna le 29 Mai 2024
Hello,
I'm writing an application to record data streaming from some data acquisition equipment over UDP, and I'm testing the application with a little code block that streams some dummy data. I want to get a feel for how fast I can parse incomming data before I can't keep up with it, but the clode block to write the data stream just isn't fast enough to test it much.
The 'real' stream consists of multiple signals of different data types that are packed together into a single multi-byte word, so I'm recreating that by typecasting different variables as 'int8', concatenating them all into a single int8 array, and then writing to the port.
Interestingly, it runs about 10x faster when I hit the 'RUN' button on this web form, but on my (quite capable) laptop it ends up running about 10x slower, or about 60 Hz. That's much slower than the situation I'm trying to recreate.
Is there a way to speed up the write? I profiled the code, and the u.write() line is 99.9% of the execution time. I can probably write batches of data instead of once for each line, but I need to match how the actual application will work.
u = udpport("datagram","LocalPort",3031);
u.OutputDatagramSize = 14;
N = 1000;
tic
for k = 1:N
data1 = single(rand());
data2 = int32(rand()*100);
data3 = int16(rand()*10000);
data4 = uint32(rand()*100000);
byteRow = [typecast(data1,'int8') typecast(data2,'int8') typecast(data3,'int8') typecast(data4,'int8')];
u.write(byteRow,"int8","localhost",3030)
end
t = toc;
disp("Seconds per Tx: " + num2str(t/N))
Seconds per Tx: 0.0011496

Réponses (1)

Poorna
Poorna le 29 Mai 2024
Hi Chris,
I see you are facing problems with slow UDP transmission. When I ran the same code in my computer on MATLAB R2024a, the time it took is 10 times slower too. I am not sure of any settings within MATLAB that will improve the transmission time. Before "udpport", the "fwrite" function along with "udp" object were used for UDP transmission. They are now deprecated, yet available for use as of R2024a and will soon be removed in a future release. When I tried the "fwrite" and "udp" functions in place of "udpport", the same code took less time in transmitting the data. If your requirement is short term, then you can use the "fwrite" and "udp" functions to send the data. Or else you could contact MathWorks help regarding the issue: https://www.mathworks.com/support/contact_us.html
Refer to the following documentation to learn more about the functions:
Hope this Helps!

Catégories

En savoir plus sur Data Acquisition Toolbox Supported Hardware dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by