-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TCP/SSL/HTTP performance testing tools
- Loading branch information
0 parents
commit ae8b318
Showing
5 changed files
with
228 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build/ |
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,11 @@ | ||
These are some tools I've been using to test performance issues related to long running HTTP requests or TCP/SSL handshake | ||
|
||
Usage: | ||
```sh | ||
concurent-http-requests <requests> <concurrency> <url> | ||
``` | ||
```sh | ||
concurrent-ssl-only <requests> <concurrency> <host:port> | ||
``` | ||
|
||
Depending where the tools will run, you should usually make sure that open file limits is high enough |
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,19 @@ | ||
#!/usr/bin/env sh | ||
|
||
script_dir="$(realpath "$(dirname "$0")")" | ||
|
||
cd "$script_dir" | ||
|
||
mkdir -p "$script_dir/build" | ||
|
||
GOOS=windows GOARCH=amd64 go build | ||
GOOS=linux GOARCH=amd64 go build | ||
|
||
mv concurrent-http* build | ||
|
||
cd "$script_dir/concurrent-ssl-only" | ||
|
||
GOOS=windows GOARCH=amd64 go build | ||
GOOS=linux GOARCH=amd64 go build | ||
|
||
mv concurrent-ssl* ../build |
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,81 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func main() { | ||
|
||
requestsCount, _ := strconv.Atoi(os.Args[1]) | ||
maxConcurrency, _ := strconv.Atoi(os.Args[2]) | ||
host := os.Args[3] | ||
|
||
dialer := &net.Dialer{ | ||
Timeout: 60 * time.Second, | ||
} | ||
|
||
config := &tls.Config{ | ||
InsecureSkipVerify: true, | ||
} | ||
|
||
concurrencyMonitor := make(chan string, maxConcurrency) | ||
|
||
concurrent := 0 | ||
|
||
requestsCountOk := 0 | ||
requestsCountFailed := 0 | ||
requestsLastError := "" | ||
|
||
lastMonitoringMessageTime := time.Now().Add(-3 * time.Second) | ||
|
||
for { | ||
if time.Now().Sub(lastMonitoringMessageTime) > 2*time.Second { | ||
fmt.Printf("remaining requests: %v, concurrent requests: %v, ok: %v, failed: %v, lastError: %v\n", requestsCount, concurrent, requestsCountOk, requestsCountFailed, requestsLastError) | ||
lastMonitoringMessageTime = time.Now() | ||
requestsCountOk = 0 | ||
requestsCountFailed = 0 | ||
requestsLastError = "" | ||
} | ||
|
||
if concurrent < maxConcurrency && requestsCount > 0 { | ||
concurrent++ | ||
requestsCount-- | ||
go DoRequest(dialer, config, host, concurrencyMonitor) | ||
} else { | ||
time.Sleep(10 * time.Microsecond) | ||
} | ||
|
||
select { | ||
case status := <-concurrencyMonitor: | ||
concurrent-- | ||
if status == "OK" { | ||
requestsCountOk++ | ||
} else { | ||
requestsCountFailed++ | ||
requestsLastError = status | ||
} | ||
default: | ||
} | ||
|
||
if requestsCount <= 0 && concurrent <= 0 { | ||
break | ||
} | ||
|
||
} | ||
} | ||
|
||
func DoRequest(dialer *net.Dialer, config *tls.Config, host string, monitor chan string) { | ||
conn, err := tls.DialWithDialer(dialer, "tcp", host, config) | ||
if err != nil { | ||
monitor <- err.Error() | ||
return | ||
} | ||
|
||
_ = conn.Close() | ||
monitor <- "OK" | ||
} |
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,116 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"io/ioutil" | ||
"net" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
func main() { | ||
|
||
requestsCount, _ := strconv.Atoi(os.Args[1]) | ||
maxConcurrency, _ := strconv.Atoi(os.Args[2]) | ||
url := os.Args[3] | ||
|
||
client := CreateClient() | ||
request, _ := CreateRequest(url) | ||
|
||
concurrencyMonitor := make(chan string, maxConcurrency) | ||
|
||
concurrent := 0 | ||
|
||
requestsCountOk := 0 | ||
requestsCountFailed := 0 | ||
requestsLastError := "" | ||
|
||
lastMonitoringMessageTime := time.Now().Add(-3 * time.Second) | ||
|
||
for { | ||
if time.Now().Sub(lastMonitoringMessageTime) > 2*time.Second { | ||
fmt.Printf("remaining requests: %v, concurrent requests: %v, ok: %v, failed: %v, lastError: %v\n", requestsCount, concurrent, requestsCountOk, requestsCountFailed, requestsLastError) | ||
lastMonitoringMessageTime = time.Now() | ||
requestsCountOk = 0 | ||
requestsCountFailed = 0 | ||
requestsLastError = "" | ||
} | ||
|
||
if concurrent < maxConcurrency && requestsCount > 0 { | ||
concurrent++ | ||
requestsCount-- | ||
go DoRequest(client, request, concurrencyMonitor) | ||
} else { | ||
time.Sleep(10 * time.Microsecond) | ||
} | ||
|
||
select { | ||
case status := <-concurrencyMonitor: | ||
concurrent-- | ||
if status == "OK" { | ||
requestsCountOk++ | ||
} else { | ||
requestsCountFailed++ | ||
requestsLastError = status | ||
} | ||
default: | ||
} | ||
|
||
if requestsCount <= 0 && concurrent <= 0 { | ||
break | ||
} | ||
|
||
} | ||
} | ||
|
||
func CreateClient() *http.Client { | ||
transport := &http.Transport{ | ||
TLSClientConfig: &tls.Config{ | ||
InsecureSkipVerify: true, | ||
}, | ||
DialContext: (&net.Dialer{ | ||
Timeout: 60 * time.Second, | ||
}).DialContext, | ||
TLSHandshakeTimeout: 120 * time.Second, | ||
ResponseHeaderTimeout: 180 * time.Second, | ||
MaxIdleConns: 0, | ||
MaxIdleConnsPerHost: 0, | ||
DisableKeepAlives: true, | ||
} | ||
client := &http.Client{ | ||
Transport: transport, | ||
Timeout: 200 * time.Second, | ||
} | ||
|
||
return client | ||
} | ||
|
||
func CreateRequest(url string) (*http.Request, error) { | ||
request, err := http.NewRequest(http.MethodGet, url, nil) | ||
if err != nil { | ||
return nil, fmt.Errorf("while creating a new request: %w", err) | ||
} | ||
request.Header.Add("Accept", "application/json") | ||
|
||
return request, nil | ||
} | ||
|
||
func DoRequest(client *http.Client, request *http.Request, monitor chan string) { | ||
response, err := client.Do(request) | ||
if err != nil { | ||
monitor <- err.Error() | ||
return | ||
} | ||
|
||
_, err = ioutil.ReadAll(response.Body) | ||
if err != nil { | ||
monitor <- err.Error() | ||
return | ||
} | ||
|
||
_ = response.Body.Close() | ||
monitor <- "OK" | ||
} |