lwip memory and full speed throughput test.
Dependencies: EthernetInterface mbed-rtos mbed
This project represents a throughtput test for the EthernetInterface, based on the lwIP library.
The purpose of this is to be able to make a comparison of full speed (Rx,Tx and Rx+Tx) and memory
between the EthernetInterface based on the lwIP and the one based on PicoTCP.
The benchmark consists of three parts:
- we are sending 1 Megabyte from the board to host
- we are waiting for the host to send us 1 Megabyte of data
- on the last part we are using a TCP Echo Server to send and receive back 1 Megabyte of data
we send/receive 1024 packets of 1024 bytes each and we measure how many bits per second we transmit and receive.
The result:
TX+RX Throughput: 4194304 bytes in 41 seconds (0.774) Mbits/s
Memory report
Current free memory : 22644 bytes
Maximum free memory : 24716 bytes
Minimum free memory : 22644 bytes
Average free memory : 22644 bytes
The python script used
#!/usr/bin/python import sys, socket import random, string import select from time import time #ECHO_SERVER_ADDRESS = "10.20.30.139" ECHO_SERVER_ADDRESS = "192.168.100.12" ECHO_SERVER_PORT = 7 N_PACKETS = 1024 LEN_PACKET = 1024 TOT_BITS = (LEN_PACKET * N_PACKETS * 8) * 4. # TX bits + RX bits PACKET = ''.join(random.choice(string.ascii_uppercase+string.digits) for _ in range(LEN_PACKET)) MEGA = 1024 * 1024. UPDATE_STEP = (N_PACKETS/20) # Make the update step such as one step = 5% UPDATE_R_STEP = (N_PACKETS/20) #Make the update step such as one step = 1% s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT)) start = time() rx_total = 0 tx_total = 0 data = '' i = 0 lp = [] p = select.poll() while(True): # keeping this in for robustness testing, when the test will run for days #Stage I - sending data from host towards mbed board print "Started sending data...." while (i < N_PACKETS): p.register(s, select.POLLOUT) lp = p.poll(1) if (len(lp) > 0): s.sendall(PACKET) i+=1 if (i % UPDATE_STEP) == 0: print "sent %d/%d (%.2f%%)" % (i, N_PACKETS, float(i)/ float(N_PACKETS) * 100.) continue #Stage II - receving data from the mbed board print "Started receiving data...." while(len(data) < N_PACKETS * LEN_PACKET): p.register(s, select.POLLIN) lp = p.poll(1) if(len(lp) > 0): r = s.recv(LEN_PACKET) if (r != ''): data += r if (len(data) / LEN_PACKET) % UPDATE_R_STEP: print "recvd %d/%d (%.2f%%)" % (len(data)/LEN_PACKET, N_PACKETS, float(len(data))/ float(N_PACKETS * LEN_PACKET) * 100.) else: print "Error receiving !" sys.exit(1) #Stage III - echo between host and mbed board print "Started echoing data...." for i in range(N_PACKETS): if (i % UPDATE_STEP) == 0: print "%.2f%%" % (float(i)/float(N_PACKETS) * 100.) s.sendall(PACKET) data = s.recv(LEN_PACKET) if (len(data) != LEN_PACKET): print "Error echoing !" sys.exit(1) print "Test was finished!" break; t = time() - start s.close() print "TX+RX Throughput: %d bytes in %d seconds (%.3f)Mbits/s" % (TOT_BITS / 8, t, ((TOT_BITS / t) / MEGA))
This test is based on the following libraries
Import librarymbed-rtos
Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
Import libraryEthernetInterface
mbed IP library over Ethernet
Click here to see the results for PicoTCP
main.cpp@1:fd8283c28901, 2013-07-09 (annotated)
- Committer:
- tass
- Date:
- Tue Jul 09 08:34:28 2013 +0000
- Revision:
- 1:fd8283c28901
- Parent:
- 0:bfe7b0aefe02
Fixed a few missing things.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tass | 0:bfe7b0aefe02 | 1 | #include <mbed.h> |
tass | 0:bfe7b0aefe02 | 2 | #include <stdarg.h> |
tass | 0:bfe7b0aefe02 | 3 | #include "EthernetInterface.h" |
tass | 0:bfe7b0aefe02 | 4 | |
tass | 0:bfe7b0aefe02 | 5 | #define ECHO_SERVER_PORT 7 |
tass | 0:bfe7b0aefe02 | 6 | #define BUFFER_QUANTITY (1024*1024) |
tass | 0:bfe7b0aefe02 | 7 | |
tass | 0:bfe7b0aefe02 | 8 | struct MemoryUsage |
tass | 0:bfe7b0aefe02 | 9 | { |
tass | 1:fd8283c28901 | 10 | uint32_t curFreeRam; |
tass | 0:bfe7b0aefe02 | 11 | uint32_t minFreeRam; |
tass | 0:bfe7b0aefe02 | 12 | uint32_t maxFreeRam; |
tass | 0:bfe7b0aefe02 | 13 | uint32_t avgFreeRam; |
tass | 0:bfe7b0aefe02 | 14 | uint32_t stackPointer; |
tass | 0:bfe7b0aefe02 | 15 | uint32_t cntSamples; |
tass | 0:bfe7b0aefe02 | 16 | }; |
tass | 0:bfe7b0aefe02 | 17 | |
tass | 1:fd8283c28901 | 18 | struct MemoryUsage memoryStats = {0,0xFFFFFFFF,0,0,0}; |
tass | 0:bfe7b0aefe02 | 19 | |
tass | 0:bfe7b0aefe02 | 20 | int fakePrintf(void* pvHeapInfo, char const* pFormatString, ...) |
tass | 0:bfe7b0aefe02 | 21 | { |
tass | 0:bfe7b0aefe02 | 22 | struct MemoryUsage * memStat = (struct MemoryUsage *)pvHeapInfo; |
tass | 0:bfe7b0aefe02 | 23 | static const char* freeRamFormat = "%d bytes in"; |
tass | 0:bfe7b0aefe02 | 24 | va_list valist; |
tass | 0:bfe7b0aefe02 | 25 | |
tass | 0:bfe7b0aefe02 | 26 | if(memcmp(pFormatString,freeRamFormat,strlen(freeRamFormat)) == 0) |
tass | 0:bfe7b0aefe02 | 27 | { |
tass | 0:bfe7b0aefe02 | 28 | va_start(valist, pFormatString); |
tass | 0:bfe7b0aefe02 | 29 | unsigned long freeSize = va_arg(valist, unsigned long); |
tass | 1:fd8283c28901 | 30 | memStat->curFreeRam = freeSize; |
tass | 0:bfe7b0aefe02 | 31 | if(memStat->minFreeRam > freeSize) |
tass | 0:bfe7b0aefe02 | 32 | memStat->minFreeRam = freeSize; |
tass | 0:bfe7b0aefe02 | 33 | |
tass | 0:bfe7b0aefe02 | 34 | if(memStat->maxFreeRam < freeSize) |
tass | 0:bfe7b0aefe02 | 35 | memStat->maxFreeRam = freeSize; |
tass | 0:bfe7b0aefe02 | 36 | |
tass | 0:bfe7b0aefe02 | 37 | memStat->avgFreeRam = ((memStat->avgFreeRam * memStat->cntSamples) + freeSize)/(++memStat->cntSamples); |
tass | 0:bfe7b0aefe02 | 38 | } |
tass | 0:bfe7b0aefe02 | 39 | else |
tass | 0:bfe7b0aefe02 | 40 | { |
tass | 0:bfe7b0aefe02 | 41 | // ignore format |
tass | 0:bfe7b0aefe02 | 42 | } |
tass | 0:bfe7b0aefe02 | 43 | return 0; |
tass | 0:bfe7b0aefe02 | 44 | } |
tass | 0:bfe7b0aefe02 | 45 | |
tass | 1:fd8283c28901 | 46 | void inline printMemoryStats(void) |
tass | 1:fd8283c28901 | 47 | { |
tass | 1:fd8283c28901 | 48 | if(memoryStats.cntSamples == 1) |
tass | 1:fd8283c28901 | 49 | printf("\n\n***** Initial Memory Report *****\n"); |
tass | 1:fd8283c28901 | 50 | else |
tass | 1:fd8283c28901 | 51 | printf("\n\n********* Memory Report *********\n"); |
tass | 1:fd8283c28901 | 52 | |
tass | 1:fd8283c28901 | 53 | printf("Current free memory : %d bytes\n",memoryStats.curFreeRam); |
tass | 1:fd8283c28901 | 54 | printf("Maximum free memory : %d bytes\n",memoryStats.maxFreeRam); |
tass | 1:fd8283c28901 | 55 | printf("Minimum free memory : %d bytes\n",memoryStats.minFreeRam); |
tass | 1:fd8283c28901 | 56 | printf("Average free memory : %d bytes\n",memoryStats.avgFreeRam); |
tass | 1:fd8283c28901 | 57 | printf("Stack pointer address : %d\n",memoryStats.stackPointer); |
tass | 1:fd8283c28901 | 58 | printf("****************************\n"); |
tass | 1:fd8283c28901 | 59 | } |
tass | 1:fd8283c28901 | 60 | |
tass | 0:bfe7b0aefe02 | 61 | void inline memoryStamp(void) |
tass | 0:bfe7b0aefe02 | 62 | { |
tass | 0:bfe7b0aefe02 | 63 | __heapstats((__heapprt)fakePrintf, &memoryStats); |
tass | 0:bfe7b0aefe02 | 64 | } |
tass | 0:bfe7b0aefe02 | 65 | |
tass | 0:bfe7b0aefe02 | 66 | void inline stackPtrSnapshot(void) |
tass | 0:bfe7b0aefe02 | 67 | { |
tass | 0:bfe7b0aefe02 | 68 | memoryStats.stackPointer = __current_sp(); |
tass | 0:bfe7b0aefe02 | 69 | } |
tass | 0:bfe7b0aefe02 | 70 | |
tass | 0:bfe7b0aefe02 | 71 | int main() { |
tass | 0:bfe7b0aefe02 | 72 | |
tass | 0:bfe7b0aefe02 | 73 | printf("Ethernet Interface memory test....\n"); |
tass | 1:fd8283c28901 | 74 | |
tass | 1:fd8283c28901 | 75 | // Initial memory status |
tass | 1:fd8283c28901 | 76 | memoryStamp(); |
tass | 0:bfe7b0aefe02 | 77 | stackPtrSnapshot(); // snapshot of the stack pointer before starting benchmark to see the SP. |
tass | 1:fd8283c28901 | 78 | printMemoryStats(); |
tass | 1:fd8283c28901 | 79 | |
tass | 0:bfe7b0aefe02 | 80 | EthernetInterface eth; |
tass | 0:bfe7b0aefe02 | 81 | int connections = 0; |
tass | 0:bfe7b0aefe02 | 82 | eth.init(); //Use DHCP |
tass | 0:bfe7b0aefe02 | 83 | eth.connect(); |
tass | 0:bfe7b0aefe02 | 84 | printf("IP Address %s\n", eth.getIPAddress()); |
tass | 0:bfe7b0aefe02 | 85 | |
tass | 0:bfe7b0aefe02 | 86 | TCPSocketServer server; |
tass | 0:bfe7b0aefe02 | 87 | server.bind(ECHO_SERVER_PORT); |
tass | 0:bfe7b0aefe02 | 88 | server.listen(); |
tass | 0:bfe7b0aefe02 | 89 | |
tass | 0:bfe7b0aefe02 | 90 | while (true) { |
tass | 0:bfe7b0aefe02 | 91 | printf("\nWait for new connection...\n"); |
tass | 0:bfe7b0aefe02 | 92 | printf("Client number %d\n",++connections); |
tass | 0:bfe7b0aefe02 | 93 | TCPSocketConnection client; |
tass | 0:bfe7b0aefe02 | 94 | server.accept(client); |
tass | 0:bfe7b0aefe02 | 95 | client.set_blocking(false, 1500); // Timeout after (1.5)s |
tass | 0:bfe7b0aefe02 | 96 | printf("Connection from: %s\n", client.get_address()); |
tass | 0:bfe7b0aefe02 | 97 | char buffer[1024]; |
tass | 0:bfe7b0aefe02 | 98 | while (true) { |
tass | 0:bfe7b0aefe02 | 99 | |
tass | 0:bfe7b0aefe02 | 100 | int dataReceived = 0; |
tass | 0:bfe7b0aefe02 | 101 | int dataSent = 0; |
tass | 0:bfe7b0aefe02 | 102 | |
tass | 0:bfe7b0aefe02 | 103 | printf("\n\n\nStarting the receiving part...\n"); |
tass | 0:bfe7b0aefe02 | 104 | while(dataReceived < BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 105 | { |
tass | 0:bfe7b0aefe02 | 106 | int n = client.receive(buffer, sizeof(buffer)); |
tass | 0:bfe7b0aefe02 | 107 | if (n <= 0) { |
tass | 0:bfe7b0aefe02 | 108 | printf("Receive error\n"); |
tass | 0:bfe7b0aefe02 | 109 | break; |
tass | 0:bfe7b0aefe02 | 110 | } |
tass | 0:bfe7b0aefe02 | 111 | dataReceived += n; |
tass | 0:bfe7b0aefe02 | 112 | memoryStamp(); |
tass | 0:bfe7b0aefe02 | 113 | } |
tass | 0:bfe7b0aefe02 | 114 | |
tass | 0:bfe7b0aefe02 | 115 | |
tass | 0:bfe7b0aefe02 | 116 | printf("Received : %d bytes\nExpected : %d bytes\n",dataReceived,BUFFER_QUANTITY); |
tass | 0:bfe7b0aefe02 | 117 | if(dataReceived < BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 118 | { |
tass | 0:bfe7b0aefe02 | 119 | printf("Receiving part of the test has failed. Exiting connection.\n"); |
tass | 0:bfe7b0aefe02 | 120 | break; |
tass | 0:bfe7b0aefe02 | 121 | } |
tass | 0:bfe7b0aefe02 | 122 | else{ |
tass | 0:bfe7b0aefe02 | 123 | printf("Receiving has passed...\n"); |
tass | 0:bfe7b0aefe02 | 124 | } |
tass | 0:bfe7b0aefe02 | 125 | |
tass | 0:bfe7b0aefe02 | 126 | printf("\n\n\nStarting the sending part...\n"); |
tass | 0:bfe7b0aefe02 | 127 | while(dataSent < BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 128 | { |
tass | 0:bfe7b0aefe02 | 129 | int n = client.send_all(buffer, sizeof(buffer)); |
tass | 0:bfe7b0aefe02 | 130 | if (n <= 0) { |
tass | 0:bfe7b0aefe02 | 131 | printf("Send error\n"); |
tass | 0:bfe7b0aefe02 | 132 | break; |
tass | 0:bfe7b0aefe02 | 133 | } |
tass | 0:bfe7b0aefe02 | 134 | dataSent += n; |
tass | 0:bfe7b0aefe02 | 135 | memoryStamp(); |
tass | 0:bfe7b0aefe02 | 136 | } |
tass | 0:bfe7b0aefe02 | 137 | |
tass | 0:bfe7b0aefe02 | 138 | printf("Sent : %d bytes\nExpected : %d bytes\n",dataSent,BUFFER_QUANTITY); |
tass | 0:bfe7b0aefe02 | 139 | if(dataSent < BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 140 | { |
tass | 0:bfe7b0aefe02 | 141 | printf("Sending part of the test has failed. Exiting connection.\n"); |
tass | 0:bfe7b0aefe02 | 142 | break; |
tass | 0:bfe7b0aefe02 | 143 | } |
tass | 0:bfe7b0aefe02 | 144 | else |
tass | 0:bfe7b0aefe02 | 145 | { |
tass | 0:bfe7b0aefe02 | 146 | printf("Sending test has passed...\n"); |
tass | 0:bfe7b0aefe02 | 147 | } |
tass | 0:bfe7b0aefe02 | 148 | |
tass | 0:bfe7b0aefe02 | 149 | |
tass | 0:bfe7b0aefe02 | 150 | printf("\n\n\nStarting echo part...\n"); |
tass | 0:bfe7b0aefe02 | 151 | dataReceived = dataSent = 0; |
tass | 0:bfe7b0aefe02 | 152 | while((dataReceived+dataSent) < 2*BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 153 | { |
tass | 0:bfe7b0aefe02 | 154 | int n = client.receive(buffer, sizeof(buffer)); |
tass | 0:bfe7b0aefe02 | 155 | if (n <= 0) { |
tass | 0:bfe7b0aefe02 | 156 | printf("Receive error\n"); |
tass | 0:bfe7b0aefe02 | 157 | break; |
tass | 0:bfe7b0aefe02 | 158 | } |
tass | 0:bfe7b0aefe02 | 159 | dataReceived += n; |
tass | 0:bfe7b0aefe02 | 160 | |
tass | 0:bfe7b0aefe02 | 161 | n = client.send_all(buffer, n); |
tass | 0:bfe7b0aefe02 | 162 | if (n <= 0) { |
tass | 0:bfe7b0aefe02 | 163 | printf("Send error\n"); |
tass | 0:bfe7b0aefe02 | 164 | break; |
tass | 0:bfe7b0aefe02 | 165 | } |
tass | 0:bfe7b0aefe02 | 166 | dataSent += n; |
tass | 0:bfe7b0aefe02 | 167 | memoryStamp(); |
tass | 0:bfe7b0aefe02 | 168 | } |
tass | 0:bfe7b0aefe02 | 169 | |
tass | 0:bfe7b0aefe02 | 170 | printf("Echo size : %d bytes\nExpected : %d bytes\n",(dataReceived+dataSent),2*BUFFER_QUANTITY); |
tass | 0:bfe7b0aefe02 | 171 | if((dataReceived+dataSent) < 2*BUFFER_QUANTITY) |
tass | 0:bfe7b0aefe02 | 172 | { |
tass | 0:bfe7b0aefe02 | 173 | printf("Echo test has failed.Exiting connection...\n"); |
tass | 0:bfe7b0aefe02 | 174 | } |
tass | 0:bfe7b0aefe02 | 175 | else |
tass | 0:bfe7b0aefe02 | 176 | { |
tass | 0:bfe7b0aefe02 | 177 | printf("Echo test has passed...\n"); |
tass | 0:bfe7b0aefe02 | 178 | } |
tass | 1:fd8283c28901 | 179 | break; |
tass | 0:bfe7b0aefe02 | 180 | } |
tass | 0:bfe7b0aefe02 | 181 | client.close(); |
tass | 1:fd8283c28901 | 182 | printf("Test was finished...\n"); |
tass | 1:fd8283c28901 | 183 | printMemoryStats(); |
tass | 0:bfe7b0aefe02 | 184 | } |
tass | 0:bfe7b0aefe02 | 185 | |
tass | 0:bfe7b0aefe02 | 186 | return 0; |
tass | 0:bfe7b0aefe02 | 187 | } |