mirror of
https://github.com/cunnie/sslip.io.git
synced 2025-10-05 15:46:50 +08:00
Introduce new flag, -max_queries_per_sec
I'm being gouged by bandwidth costs by AWS. Last month's bill was $148, and all but $9 was about bandwidth. My bandwidth has been inexplicably climbing since February: Billing Month Total GB % increase 2024/2 37.119 2024/3 52.953 42.66% 2024/4 58.745 10.94% 2024/5 69.307 17.98% 2024/6 173.371 150.15% 2024/7 334.064 92.69% 2024/8 539.343 61.45% 2024/9 568.745 5.45% 2024/10 1365.305 140.06% The new flag will allow me to throttle the AWS bandwidth to ~287 queries / second, which, according to my calculations, will max out the free 100 GB bandwidth without dipping into the for-pay bandwidth.
This commit is contained in:
@@ -14,8 +14,14 @@ import (
|
||||
var _ = Describe("flags", func() {
|
||||
var serverCmd *exec.Cmd
|
||||
var serverSession *Session
|
||||
var port = getFreePort()
|
||||
var port int
|
||||
var flags []string
|
||||
var serverReadyOrDeadOutput string
|
||||
|
||||
BeforeEach(func() {
|
||||
port = getFreePort()
|
||||
serverReadyOrDeadOutput = "Ready to answer queries"
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
flags = append(flags, "-port", strconv.Itoa(port), "-blocklistURL", "file://etc/blocklist-test.txt")
|
||||
@@ -25,7 +31,7 @@ var _ = Describe("flags", func() {
|
||||
// takes 0.455s to start up on macOS Big Sur 3.7 GHz Quad Core 22-nm Xeon E5-1620v2 processor (2013 Mac Pro)
|
||||
// takes 1.312s to start up on macOS Big Sur 2.0GHz quad-core 10th-generation Intel Core i5 processor (2020 13" MacBook Pro)
|
||||
// 10 seconds should be long enough for slow container-on-a-VM-with-shared-core
|
||||
Eventually(serverSession.Err, 10).Should(Say("Ready to answer queries"))
|
||||
Eventually(serverSession.Err, 10).Should(Say(serverReadyOrDeadOutput))
|
||||
})
|
||||
AfterEach(func() {
|
||||
serverSession.Terminate()
|
||||
@@ -234,4 +240,50 @@ var _ = Describe("flags", func() {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
When("-max_queries_per_sec is set", func() {
|
||||
When("the arguments are missing", func() {
|
||||
BeforeEach(func() {
|
||||
flags = []string{"-max_queries_per_sec="}
|
||||
serverReadyOrDeadOutput = "-max_queries_per_sec: parse error"
|
||||
})
|
||||
It("should give an informative message", func() {
|
||||
portFail := getFreePort()
|
||||
flags = append(flags, "-port", strconv.Itoa(portFail), "-blocklistURL", "file://etc/blocklist-test.txt")
|
||||
serverCmd = exec.Command(serverPath, flags...)
|
||||
serverSessionFail, err := Start(serverCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// takes 0.455s to start up on macOS Big Sur 3.7 GHz Quad Core 22-nm Xeon E5-1620v2 processor (2013 Mac Pro)
|
||||
// takes 1.312s to start up on macOS Big Sur 2.0GHz quad-core 10th-generation Intel Core i5 processor (2020 13" MacBook Pro)
|
||||
// 10 seconds should be long enough for slow container-on-a-VM-with-shared-core
|
||||
Eventually(serverSessionFail.Err, 10).Should(Say(serverReadyOrDeadOutput))
|
||||
Eventually(string(serverSessionFail.Err.Contents())).Should(MatchRegexp(`-max_queries_per_sec`))
|
||||
})
|
||||
})
|
||||
When("the queries exceed the limit", func() {
|
||||
BeforeEach(func() {
|
||||
flags = []string{"-max_queries_per_sec=1"}
|
||||
})
|
||||
It("should answer the first query but not the second", func() {
|
||||
digArgs := "@localhost 169-254-169-254.sslip.io +tries=1 +timeout=1 -p " + strconv.Itoa(port)
|
||||
digCmd := exec.Command("dig", strings.Split(digArgs, " ")...)
|
||||
digSession, err := Start(digCmd, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(digSession).Should(Say(`flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0`))
|
||||
Eventually(digSession).Should(Say(`;; ANSWER SECTION:`))
|
||||
Eventually(digSession).Should(Say(`169-254-169-254.sslip.io. 3600 IN A 169.254.169.254\n`))
|
||||
Eventually(digSession, 1).Should(Exit(0))
|
||||
Eventually(string(serverSession.Err.Contents())).Should(MatchRegexp(`TypeA 169-254-169-254\.sslip\.io\. \? 169\.254\.169\.254`))
|
||||
// second command, same as the first, but is throttled and doesn't get a DNS reply
|
||||
digCmdThrottled := exec.Command("dig", strings.Split(digArgs, " ")...)
|
||||
digSessionThrottled, err := Start(digCmdThrottled, GinkgoWriter, GinkgoWriter)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Eventually(digSessionThrottled, 2).Should(Exit(0))
|
||||
Eventually(string(serverSession.Err.Contents())).Should(MatchRegexp(`429 Too Many Requests: .* queries per second exceeds 1 queries per second limit`))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
When("-max_queries_per_sec is set", func() {
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user