-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
vttablet throttling #6668
Merged
Merged
vttablet throttling #6668
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
6b5617c
enable and set heartbeat in examples' vttablet-up.sh
shlomi-noach afb62af
majority of freno import
shlomi-noach 63d29f7
using a lagThrottler from within tabletserver/tm_state
shlomi-noach 4652408
Correct usage of Open/Close and leadership check. Kicking Operate().
shlomi-noach 2ba4afc
fixed heartbeat_enable flag name
shlomi-noach fc01e9c
/throttler/status endpoint
shlomi-noach 9d2882d
Pretty much complete logic, supporting reparenting and rotating accounts
shlomi-noach 01cabe4
Pretty much complete logic, supporting reparenting and rotating accounts
shlomi-noach 8213c8e
fix tabletserver unit test
shlomi-noach 155124f
double check read_only state
shlomi-noach 6573d44
Added endtoend throttler_test
shlomi-noach b5958e7
test no hosts, test restoring hosts
shlomi-noach 1e4c01a
test the throttler\?
shlomi-noach c9807c8
enable heartbeat; test replication lag, test no hosts
shlomi-noach 0dec65d
heartbeat interval for example apps: 250ms
shlomi-noach 0813733
introducing -throttle_threshold tablet command line flag
shlomi-noach 9ec3ad5
Merge branch 'master' into vttablet-throttle
shlomi-noach e39c8ed
copyright 2020
shlomi-noach b51b8f9
license in every file
shlomi-noach 053f3e3
copyright 2020
shlomi-noach 2f5ce5d
Adding freno's original license by GitHub
shlomi-noach e13ae74
Operate() starts on every Open() call, temrinates on any Close() call
shlomi-noach bbde649
Adding SuspendableTicker
shlomi-noach c3dfcab
changes Open()/Close() logic, using suspendable timers. Also, overcom…
shlomi-noach b9d4314
fixed state_manager_test
shlomi-noach 4c050ef
Merge remote-tracking branch 'upstream/master' into vttablet-throttle
shlomi-noach 992c38f
HTTP 200 OK when no replicas exist
shlomi-noach 3669283
-throttle_tablet_types command line flag
shlomi-noach 4b0a5a3
throttle according to throttle_tablet_types
shlomi-noach 48e62e3
fixes per review
shlomi-noach 62d2d82
fixes per review
shlomi-noach 7f1de38
reorder throttler.Close()
shlomi-noach 567271b
adapt state_manager test
shlomi-noach 4d09259
throttler implicitly enables heartbeat
shlomi-noach 047352a
removed DefaultMySQLPort
shlomi-noach 60a4082
enable/disable heartbeat; fix tests
shlomi-noach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
197 changes: 197 additions & 0 deletions
197
go/test/endtoend/tabletmanager/throttler/throttler_test.go
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,197 @@ | ||
/* | ||
Copyright 2020 The Vitess Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
package master | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
"testing" | ||
"time" | ||
|
||
"vitess.io/vitess/go/vt/vttablet/tabletserver/throttle/base" | ||
|
||
"vitess.io/vitess/go/test/endtoend/cluster" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
var ( | ||
clusterInstance *cluster.LocalProcessCluster | ||
masterTablet cluster.Vttablet | ||
replicaTablet cluster.Vttablet | ||
hostname = "localhost" | ||
keyspaceName = "ks" | ||
cell = "zone1" | ||
sqlSchema = ` | ||
create table t1( | ||
id bigint, | ||
value varchar(16), | ||
primary key(id) | ||
) Engine=InnoDB; | ||
` | ||
|
||
vSchema = ` | ||
{ | ||
"sharded": true, | ||
"vindexes": { | ||
"hash": { | ||
"type": "hash" | ||
} | ||
}, | ||
"tables": { | ||
"t1": { | ||
"column_vindexes": [ | ||
{ | ||
"column": "id", | ||
"name": "hash" | ||
} | ||
] | ||
} | ||
} | ||
}` | ||
|
||
httpClient = base.SetupHTTPClient(time.Second) | ||
checkAPIPath = "throttler/check" | ||
) | ||
|
||
func TestMain(m *testing.M) { | ||
defer cluster.PanicHandler(nil) | ||
flag.Parse() | ||
|
||
exitCode := func() int { | ||
clusterInstance = cluster.NewCluster(cell, hostname) | ||
defer clusterInstance.Teardown() | ||
|
||
// Start topo server | ||
err := clusterInstance.StartTopo() | ||
if err != nil { | ||
return 1 | ||
} | ||
|
||
// Set extra tablet args for lock timeout | ||
clusterInstance.VtTabletExtraArgs = []string{ | ||
"-lock_tables_timeout", "5s", | ||
"-watch_replication_stream", | ||
"-enable_replication_reporter", | ||
"-heartbeat_enable", | ||
"-heartbeat_interval", "250ms", | ||
} | ||
// We do not need semiSync for this test case. | ||
clusterInstance.EnableSemiSync = false | ||
|
||
// Start keyspace | ||
keyspace := &cluster.Keyspace{ | ||
Name: keyspaceName, | ||
SchemaSQL: sqlSchema, | ||
VSchema: vSchema, | ||
} | ||
|
||
if err = clusterInstance.StartUnshardedKeyspace(*keyspace, 1, false); err != nil { | ||
return 1 | ||
} | ||
|
||
// Collect table paths and ports | ||
tablets := clusterInstance.Keyspaces[0].Shards[0].Vttablets | ||
for _, tablet := range tablets { | ||
if tablet.Type == "master" { | ||
masterTablet = *tablet | ||
} else if tablet.Type != "rdonly" { | ||
replicaTablet = *tablet | ||
} | ||
} | ||
|
||
return m.Run() | ||
}() | ||
os.Exit(exitCode) | ||
} | ||
|
||
func throttleCheck() (*http.Response, error) { | ||
return httpClient.Head(fmt.Sprintf("http://localhost:%d/%s", masterTablet.HTTPPort, checkAPIPath)) | ||
} | ||
|
||
func TestThrottlerBeforeMetricsCollected(t *testing.T) { | ||
defer cluster.PanicHandler(t) | ||
|
||
// Immediately after startup, we expect this response: | ||
// {"StatusCode":404,"Value":0,"Threshold":0,"Message":"No such metric"} | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusNotFound, resp.StatusCode) | ||
} | ||
|
||
func TestThrottlerAfterMetricsCollected(t *testing.T) { | ||
defer cluster.PanicHandler(t) | ||
|
||
time.Sleep(10 * time.Second) | ||
// By this time metrics will have been collected. We expect no lag, and something like: | ||
// {"StatusCode":200,"Value":0.282278,"Threshold":1,"Message":""} | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
|
||
func TestLag(t *testing.T) { | ||
defer cluster.PanicHandler(t) | ||
|
||
{ | ||
err := clusterInstance.VtctlclientProcess.ExecuteCommand("StopReplication", replicaTablet.Alias) | ||
assert.NoError(t, err) | ||
|
||
time.Sleep(2 * time.Second) | ||
// Lag will have accumulated | ||
// {"StatusCode":429,"Value":4.864921,"Threshold":1,"Message":"Threshold exceeded"} | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusTooManyRequests, resp.StatusCode) | ||
} | ||
{ | ||
err := clusterInstance.VtctlclientProcess.ExecuteCommand("StartReplication", replicaTablet.Alias) | ||
assert.NoError(t, err) | ||
|
||
time.Sleep(5 * time.Second) | ||
// Restore | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
} | ||
|
||
func TestNoReplicas(t *testing.T) { | ||
defer cluster.PanicHandler(t) | ||
{ | ||
err := clusterInstance.VtctlclientProcess.ExecuteCommand("ChangeTabletType", replicaTablet.Alias, "RDONLY") | ||
assert.NoError(t, err) | ||
|
||
time.Sleep(10 * time.Second) | ||
// This makes no REPLICA servers available. We expect something like: | ||
// {"StatusCode":200,"Value":0,"Threshold":1,"Message":""} | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
{ | ||
err := clusterInstance.VtctlclientProcess.ExecuteCommand("ChangeTabletType", replicaTablet.Alias, "REPLICA") | ||
assert.NoError(t, err) | ||
|
||
time.Sleep(10 * time.Second) | ||
// Restore valid replica | ||
resp, err := throttleCheck() | ||
assert.NoError(t, err) | ||
assert.Equal(t, http.StatusOK, resp.StatusCode) | ||
} | ||
} |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test, and the next one, is doing fair amount of
time.Sleep
. Is there no way to speed these tests up a bit?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the way to speed this up is to make the throttler's roster polling interval smaller, and to implement that by adding a new configuration variable. However, does it make sense to only add this configuration variable for purposes of CI tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense for users to configure the polling interval?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my answer to @harshit-gangal : #6668 (comment)