-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
177 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @Author: hiram | ||
* @Date: 2020/7/9 9:20 | ||
*/ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"gitee.com/gbat/goperf" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
var ( | ||
server = flag.Bool("s", false, "default:start on tcp client ,select true for start on tcp server.") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
if *server { | ||
goperf.Server() | ||
} else { | ||
goperf.Client() | ||
} | ||
|
||
sigs := make(chan os.Signal, 1) | ||
done := make(chan bool, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
go func() { | ||
sig := <-sigs | ||
fmt.Println() | ||
fmt.Println(sig) | ||
done <- true | ||
}() | ||
fmt.Println("awaiting signal") | ||
<-done | ||
fmt.Println("exiting") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package goperf | ||
|
||
import ( | ||
"encoding/binary" | ||
"flag" | ||
"fmt" | ||
"net" | ||
) | ||
|
||
var ( | ||
flocalPort = flag.Int("port", 10001, "Port to listen on.") | ||
flocalIp = flag.String("ip", "127.0.0.1", "IP to listen on.") | ||
keepAlive = flag.Bool("k", false, "is keep alive") | ||
testType = flag.Bool("io", false, "test type,either 'concurrency' or 'IOPS'.") | ||
buffer = flag.Int64("b", 500, "send bytes,unit: B.") | ||
) | ||
|
||
func receive(conn net.Conn) { | ||
if !*keepAlive { | ||
defer conn.Close() | ||
} | ||
size := int64(256 * 1024) | ||
if !*testType { | ||
size = *buffer | ||
} | ||
if *testType { | ||
size = 256 * 1024 | ||
} | ||
buf := make([]byte, size) | ||
var total uint64 | ||
for { | ||
n, err := conn.Read(buf) | ||
total += uint64(n) | ||
if err != nil { | ||
fmt.Println("Connection finishes with", total, "bytes:", err) | ||
return | ||
} | ||
if err := binary.Write(conn, binary.BigEndian, total); err != nil { | ||
panic(err) | ||
} | ||
} | ||
} | ||
|
||
func accept(listener net.Listener) { | ||
for { | ||
conn, err := listener.Accept() | ||
if err != nil { | ||
fmt.Println(err) | ||
break | ||
} | ||
go receive(conn) | ||
} | ||
} | ||
|
||
func Server() { | ||
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{ | ||
IP: net.ParseIP(*flocalIp), | ||
Port: *flocalPort, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
go accept(listener) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.