-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make sure we can build ndt-server on macOS
We don't support macOS officially. However it's useful to build on a system that is different from the containers where we deploy. As mentioned in #100, I am convinced that Travis is different enough from the containers where we deploy to look like macOS.
- Loading branch information
1 parent
63240a9
commit 890c971
Showing
4 changed files
with
80 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package web100 | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"log" | ||
"os" | ||
"time" | ||
|
||
"golang.org/x/sys/unix" | ||
) | ||
|
||
func summarize(snaps []*unix.TCPInfo) (*Metrics, error) { | ||
if len(snaps) == 0 { | ||
return nil, errors.New("zero-length list of data collected") | ||
} | ||
minrtt := uint32(0) | ||
for _, snap := range snaps { | ||
if snap.Rtt < minrtt || minrtt == 0 { | ||
minrtt = snap.Rtt | ||
} | ||
} | ||
info := &Metrics{MinRTT: minrtt / 1000} // Convert microseconds to milliseconds. | ||
log.Println("Summarized data:", info) | ||
return info, nil | ||
} | ||
|
||
// MeasureViaPolling collects all required data by polling. It is required for | ||
// non-BBR connections because MinRTT is one of our critical metrics. | ||
func MeasureViaPolling(ctx context.Context, fp *os.File, c chan *Metrics) { | ||
defer close(c) | ||
ticker := time.NewTicker(100 * time.Millisecond) | ||
defer ticker.Stop() | ||
snaps := make([]*unix.TCPInfo, 0, 100) | ||
// Poll until the context is canceled. | ||
for { | ||
// Get the tcp_cc metrics | ||
info, err := unix.GetsockoptTCPInfo(int(fp.Fd()), unix.IPPROTO_TCP, unix.TCP_INFO) | ||
if err == nil { | ||
snaps = append(snaps, info) | ||
} else { | ||
log.Println("Getsockopt error:", err) | ||
} | ||
select { | ||
case <-ticker.C: | ||
continue | ||
case <-ctx.Done(): | ||
info, err := summarize(snaps) | ||
if err == nil { | ||
c <- info | ||
} | ||
return | ||
} | ||
} | ||
} | ||
|
||
// TODO: Implement BBR support for legacy clients. | ||
/* | ||
func MeasureBBR(ctx context.Context, fp *os.File) (Metrics, error) { | ||
return Metrics{}, errors.New("MeasureBBR is unimplemented") | ||
} | ||
*/ |
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,14 @@ | ||
// +build !linux | ||
|
||
package web100 | ||
|
||
import ( | ||
"context" | ||
"os" | ||
) | ||
|
||
// MeasureViaPolling collects all required data by polling. It is required for | ||
// non-BBR connections because MinRTT is one of our critical metrics. | ||
func MeasureViaPolling(ctx context.Context, fp *os.File, c chan *Metrics) { | ||
// Just a stub. | ||
} |