Improve throttling and take input as bits/s instead of bytes/s (#136)

* Take rate input as bits/s

* Update README.md

* Fix throttling to be as precise as possible.

* Minor doc fix.

* Update README.md
This commit is contained in:
Pankaj Garg 2020-11-30 21:44:25 -08:00 committed by GitHub
parent 945d59c33b
commit 8f994d1400
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 14 deletions

View file

@ -217,9 +217,9 @@ In this mode, Ethr client can only talk to an Ethr server.
Run in client mode and connect to <server>. Run in client mode and connect to <server>.
Server is specified using name, FQDN or IP address. Server is specified using name, FQDN or IP address.
-b <rate> -b <rate>
Bytes to send per second (format: <num>[KB | MB | GB]) Transmit only Bits per second (format: <num>[K | M | G])
Only valid for Bandwidth tests. Default: 0 - Unlimited Only valid for Bandwidth tests. Default: 0 - Unlimited
Examples: 100 (100B/s or 800bits/s), 1MB (1MB/s or 8Mbits/s). Examples: 100 (100bits/s), 1M (1Mbits/s).
-cport <number> -cport <number>
Use specified local port number in client for TCP & UDP tests. Use specified local port number in client for TCP & UDP tests.
Default: 0 - Ephemeral Port Default: 0 - Ephemeral Port

View file

@ -259,9 +259,6 @@ func runTCPBandwidthTestHandler(test *ethrTest, conn net.Conn, wg *sync.WaitGrou
ui.printMsg("[%3d] local %s port %s connected to %s port %s", ui.printMsg("[%3d] local %s port %s connected to %s port %s",
ec.fd, lserver, lport, rserver, rport) ec.fd, lserver, lport, rserver, rport)
size := test.clientParam.BufferSize size := test.clientParam.BufferSize
if test.clientParam.BwRate > 0 && uint64(size) > test.clientParam.BwRate {
size = uint32(test.clientParam.BwRate)
}
buff := make([]byte, size) buff := make([]byte, size)
for i := uint32(0); i < size; i++ { for i := uint32(0); i < size; i++ {
buff[i] = byte(i) buff[i] = byte(i)
@ -959,9 +956,6 @@ func runUDPBandwidthAndPpsTest(test *ethrTest) {
for th := uint32(0); th < test.clientParam.NumThreads; th++ { for th := uint32(0); th < test.clientParam.NumThreads; th++ {
go func(th uint32) { go func(th uint32) {
size := test.clientParam.BufferSize size := test.clientParam.BufferSize
if test.clientParam.BwRate > 0 && uint64(size) > test.clientParam.BwRate {
size = uint32(test.clientParam.BwRate)
}
buff := make([]byte, size) buff := make([]byte, size)
conn, err := ethrDialInc(UDP, test.dialAddr, uint16(th)) conn, err := ethrDialInc(UDP, test.dialAddr, uint16(th))
if err != nil { if err != nil {

14
ethr.go
View file

@ -201,6 +201,14 @@ func main() {
bwRate := uint64(0) bwRate := uint64(0)
if *bwRateStr != "" { if *bwRateStr != "" {
bwRate = unitToNumber(*bwRateStr) bwRate = unitToNumber(*bwRateStr)
bwRate /= 8
}
// Adjust the numbers so that data can be transfered in equal units.
if bwRate > 0 {
factor := (bwRate + bufLen - 1) / bufLen
bufLen = bwRate / factor
bwRate = bufLen * factor
} }
// //
@ -503,7 +511,7 @@ func printGapUsage() {
func printBufLenUsage() { func printBufLenUsage() {
printFlagUsage("l", "<length>", printFlagUsage("l", "<length>",
"Length of buffer to use (format: <num>[KB | MB | GB])", "Length of buffer (in Bytes) to use (format: <num>[KB | MB | GB])",
"Only valid for Bandwidth tests. Max 1GB.", "Only valid for Bandwidth tests. Max 1GB.",
"Default: 16KB") "Default: 16KB")
} }
@ -552,9 +560,9 @@ func printToSUsage() {
func printBwRateUsage() { func printBwRateUsage() {
printFlagUsage("b", "<rate>", printFlagUsage("b", "<rate>",
"Bytes to send per second (format: <num>[KB | MB | GB])", "Transmit only Bits per second (format: <num>[K | M | G])",
"Only valid for Bandwidth tests. Default: 0 - Unlimited", "Only valid for Bandwidth tests. Default: 0 - Unlimited",
"Examples: 100 (100B/s or 800bits/s), 1MB (1MB/s or 8Mbits/s).") "Examples: 100 (100bits/s), 1M (1Mbits/s).")
} }
func printCPortUsage() { func printCPortUsage() {

View file

@ -145,9 +145,6 @@ func srvrHandleNewTcpConn(conn net.Conn) {
func srvrRunTCPBandwidthTest(test *ethrTest, clientParam EthrClientParam, conn net.Conn) { func srvrRunTCPBandwidthTest(test *ethrTest, clientParam EthrClientParam, conn net.Conn) {
size := clientParam.BufferSize size := clientParam.BufferSize
if clientParam.BwRate > 0 && uint64(size) > clientParam.BwRate {
size = uint32(clientParam.BwRate)
}
buff := make([]byte, size) buff := make([]byte, size)
for i := uint32(0); i < size; i++ { for i := uint32(0); i < size; i++ {
buff[i] = byte(i) buff[i] = byte(i)