Skip to content

Commit eecec66

Browse files
committed
WIP
Signed-off-by: Brendan Dougherty <[email protected]>
1 parent e1151b9 commit eecec66

File tree

7 files changed

+127
-3
lines changed

7 files changed

+127
-3
lines changed

examples/local/101_initial_cluster.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,7 @@ vtctldclient ApplyVSchema --vschema-file vschema_commerce_initial.json commerce
6969
CELL=zone1 ./scripts/vtgate-up.sh
7070

7171
# start vtadmin
72-
./scripts/vtadmin-up.sh
72+
#./scripts/vtadmin-up.sh
7373

74+
echo "Making 100 the primary"
75+
vtctlclient PlannedReparentShard -- --keyspace_shard=commerce/0 --new_primary=zone1-0000000100

examples/local/401_teardown.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
source ./env.sh
2121

22-
./scripts/vtadmin-down.sh
22+
#./scripts/vtadmin-down.sh
2323

2424
./scripts/vtorc-down.sh
2525

examples/local/run_queries.go

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"log"
7+
"os"
8+
"sync"
9+
"time"
10+
11+
_ "vitess.io/vitess/go/vt/vtctl/grpcvtctlclient"
12+
_ "vitess.io/vitess/go/vt/vtgate/grpcvtgateconn"
13+
"vitess.io/vitess/go/vt/vtgate/vtgateconn"
14+
)
15+
16+
const NumQueries = 10000
17+
const Concurrency = 100
18+
const ShouldDelay = false
19+
const Delay = 100 * time.Millisecond
20+
21+
func main() {
22+
connectCtx, connectCancel := context.WithTimeout(context.Background(), 1*time.Second)
23+
defer connectCancel()
24+
25+
fmt.Println("Connecting")
26+
conn, err := vtgateconn.Dial(connectCtx, "localhost:15991")
27+
if err != nil {
28+
log.Fatal(err)
29+
}
30+
defer conn.Close()
31+
32+
session := conn.Session("commerce", nil)
33+
34+
var wg sync.WaitGroup
35+
wg.Add(Concurrency)
36+
37+
tasks := make(chan int, NumQueries)
38+
39+
for i := 0; i < Concurrency; i++ {
40+
go func(id int) {
41+
defer wg.Done()
42+
for range tasks {
43+
duration, err := runQuery(session)
44+
if err != nil {
45+
fmt.Printf("%v %v\n", duration, err)
46+
os.Exit(1)
47+
}
48+
//fmt.Println(duration)
49+
if ShouldDelay {
50+
time.Sleep(Delay)
51+
}
52+
}
53+
}(i)
54+
}
55+
56+
// Enqueue X tasks
57+
for i := 0; i < NumQueries; i++ {
58+
tasks <- i
59+
}
60+
61+
// Close the channel to signal to the goroutines that no more tasks will be added
62+
close(tasks)
63+
64+
// Wait for all goroutines to finish
65+
wg.Wait()
66+
}
67+
68+
func runQuery(session *vtgateconn.VTGateSession) (time.Duration, error) {
69+
queryCtx, queryCancel := context.WithTimeout(context.Background(), 1*time.Second)
70+
defer queryCancel()
71+
start := time.Now()
72+
_, err := session.Execute(queryCtx, "SELECT * FROM customer", nil)
73+
end := time.Now()
74+
return end.Sub(start), err
75+
}

examples/local/scripts/vtgate-up.sh

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ mysql_server_socket_path="/tmp/mysql.sock"
2828
# shellcheck disable=SC2086
2929
vtgate \
3030
$TOPOLOGY_FLAGS \
31+
--alsologtostderr \
3132
--log_dir $VTDATAROOT/tmp \
3233
--log_queries_to_file $VTDATAROOT/tmp/vtgate_querylog.txt \
3334
--port $web_port \

examples/local/scripts/vttablet-up.sh

+12
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ echo "Starting vttablet for $alias..."
3838
# shellcheck disable=SC2086
3939
vttablet \
4040
$TOPOLOGY_FLAGS \
41+
--alsologtostderr \
4142
--log_dir $VTDATAROOT/tmp \
4243
--log_queries_to_file $VTDATAROOT/tmp/$tablet_logfile \
4344
--tablet-path $alias \
@@ -55,6 +56,17 @@ vttablet \
5556
--service_map 'grpc-queryservice,grpc-tabletmanager,grpc-updatestream' \
5657
--pid_file $VTDATAROOT/$tablet_dir/vttablet.pid \
5758
--vtctld_addr http://$hostname:$vtctld_web_port/ \
59+
--enable_consolidator=false \
60+
--enable_consolidator_replicas=false \
61+
--queryserver-config-pool-size 100 \
62+
--queryserver-config-query-pool-timeout 0.1 \
63+
--queryserver-config-query-pool-waiter-cap 100 \
64+
--queryserver-config-transaction-cap 100 \
65+
--queryserver-config-txpool-timeout 0.1 \
66+
--queryserver-config-txpool-waiter-cap 100 \
67+
--queryserver-config-stream-pool-size 100 \
68+
--queryserver-config-stream-pool-timeout 0.1 \
69+
--queryserver-config-stream-pool-waiter-cap 100 \
5870
--disable_active_reparents \
5971
> $VTDATAROOT/$tablet_dir/vttablet.out 2>&1 &
6072

go/pools/resource_pool.go

+30
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ type (
110110

111111
reopenMutex sync.Mutex
112112
refresh *poolRefresh
113+
verbose sync2.AtomicBool
113114
}
114115
)
115116

@@ -180,6 +181,10 @@ func NewResourcePool(factory Factory, capacity, maxCap int, idleTimeout time.Dur
180181
return rp
181182
}
182183

184+
func (rp *ResourcePool) Verbose(v bool) {
185+
rp.verbose.Set(v)
186+
}
187+
183188
func (rp *ResourcePool) Name() string {
184189
return "ResourcePool"
185190
}
@@ -263,6 +268,7 @@ func (rp *ResourcePool) Get(ctx context.Context, setting *Setting) (resource Res
263268
}
264269

265270
func (rp *ResourcePool) get(ctx context.Context) (resource Resource, err error) {
271+
rp.verboseInfo("AYO getting a resource without settings")
266272
rp.getCount.Add(1)
267273
// Fetch
268274
var wrapper resourceWrapper
@@ -274,19 +280,24 @@ func (rp *ResourcePool) get(ctx context.Context) (resource Resource, err error)
274280
// check normal resources first
275281
case wrapper, ok = <-rp.resources:
276282
default:
283+
rp.verboseInfo("AYO nothing in rp.resources")
277284
select {
278285
// then checking setting resources
279286
case wrapper, ok = <-rp.settingResources:
280287
default:
288+
rp.verboseInfo("AYO nothing in rp.settingResources")
289+
rp.verboseInfo("AYO waiting for a resource")
281290
// now waiting
282291
startTime := time.Now()
283292
select {
284293
case wrapper, ok = <-rp.resources:
285294
case wrapper, ok = <-rp.settingResources:
286295
case <-ctx.Done():
296+
rp.verboseError("AYO timed out waiting for a resource")
287297
return nil, ErrTimeout
288298
}
289299
rp.recordWait(startTime)
300+
rp.verboseInfo("AYO got a resource after waiting")
290301
}
291302
}
292303
if !ok {
@@ -295,6 +306,7 @@ func (rp *ResourcePool) get(ctx context.Context) (resource Resource, err error)
295306

296307
// if the resource has setting applied, we will close it and return a new one
297308
if wrapper.resource != nil && wrapper.resource.IsSettingApplied() {
309+
rp.verboseInfo("AYO got a resource with settings applied. Gonna reset it.")
298310
rp.resetSettingCount.Add(1)
299311
err = wrapper.resource.ResetSetting(ctx)
300312
if err != nil {
@@ -307,20 +319,38 @@ func (rp *ResourcePool) get(ctx context.Context) (resource Resource, err error)
307319

308320
// Unwrap
309321
if wrapper.resource == nil {
322+
rp.verboseInfo("AYO gonna create a new resource.")
310323
wrapper.resource, err = rp.factory(ctx)
311324
if err != nil {
312325
rp.resources <- resourceWrapper{}
326+
rp.verboseError("AYO error creating resource: %s", err)
313327
return nil, err
314328
}
329+
rp.verboseInfo("AYO created a resource")
315330
rp.active.Add(1)
316331
}
332+
333+
rp.verboseInfo("AYO got a resource now (from pool or just created)")
334+
317335
if rp.available.Add(-1) <= 0 {
318336
rp.exhausted.Add(1)
319337
}
320338
rp.inUse.Add(1)
321339
return wrapper.resource, err
322340
}
323341

342+
func (rp *ResourcePool) verboseInfo(format string, args ...interface{}) {
343+
if rp.verbose.Get() {
344+
log.Infof(format, args...)
345+
}
346+
}
347+
348+
func (rp *ResourcePool) verboseError(format string, args ...interface{}) {
349+
if rp.verbose.Get() {
350+
log.Infof(format, args...)
351+
}
352+
}
353+
324354
func (rp *ResourcePool) getWithSettings(ctx context.Context, setting *Setting) (Resource, error) {
325355
rp.getSettingCount.Add(1)
326356
var wrapper resourceWrapper

go/vt/vttablet/tabletserver/connpool/pool.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func (cp *Pool) Open(appParams, dbaParams, appDebugParams dbconfigs.Connector) {
134134
refreshCheck = netutil.DNSTracker(appParams.Host())
135135
}
136136

137-
cp.connections = pools.NewResourcePool(f, cp.capacity, cp.capacity, cp.idleTimeout, cp.getLogWaitCallback(), refreshCheck, mysqlctl.PoolDynamicHostnameResolution)
137+
pool := pools.NewResourcePool(f, cp.capacity, cp.capacity, cp.idleTimeout, cp.getLogWaitCallback(), refreshCheck, mysqlctl.PoolDynamicHostnameResolution)
138+
if cp.name == "ConnPool" {
139+
pool.Verbose(true)
140+
}
141+
cp.connections = pool
138142
cp.appDebugParams = appDebugParams
139143

140144
cp.dbaPool.Open(dbaParams)

0 commit comments

Comments
 (0)