Просмотр исходного кода

Include initialization time in establishment_duration

- Excluding initialization time masks slow establishment durations
  for clients with slow datastore operations.
Rod Hynes 5 лет назад
Родитель
Сommit
39f5889632
1 измененных файлов с 14 добавлено и 8 удалено
  1. 14 8
      psiphon/controller.go

+ 14 - 8
psiphon/controller.go

@@ -56,6 +56,7 @@ type Controller struct {
 	tunnels                                 []*Tunnel
 	tunnels                                 []*Tunnel
 	nextTunnel                              int
 	nextTunnel                              int
 	isEstablishing                          bool
 	isEstablishing                          bool
+	establishStartTime                      time.Time
 	protocolSelectionConstraints            *protocolSelectionConstraints
 	protocolSelectionConstraints            *protocolSelectionConstraints
 	concurrentEstablishTunnelsMutex         sync.Mutex
 	concurrentEstablishTunnelsMutex         sync.Mutex
 	establishConnectTunnelCount             int
 	establishConnectTunnelCount             int
@@ -1203,6 +1204,12 @@ func (controller *Controller) startEstablishing() {
 	}
 	}
 	NoticeInfo("start establishing")
 	NoticeInfo("start establishing")
 
 
+	// establishStartTime is used to calculate and report the client's tunnel
+	// establishment duration. Establishment duration should include all
+	// initialization in launchEstablishing and establishCandidateGenerator,
+	// including any potentially long-running datastore iterations.
+	establishStartTime := time.Now()
+
 	controller.concurrentEstablishTunnelsMutex.Lock()
 	controller.concurrentEstablishTunnelsMutex.Lock()
 	controller.establishConnectTunnelCount = 0
 	controller.establishConnectTunnelCount = 0
 	controller.concurrentEstablishTunnels = 0
 	controller.concurrentEstablishTunnels = 0
@@ -1214,10 +1221,11 @@ func (controller *Controller) startEstablishing() {
 	DoGarbageCollection()
 	DoGarbageCollection()
 	emitMemoryMetrics()
 	emitMemoryMetrics()
 
 
-	// Note: the establish context cancelFunc, controller.stopEstablish,
-	// is called in controller.stopEstablishing.
+	// The establish context cancelFunc, controller.stopEstablish, is called in
+	// controller.stopEstablishing.
 
 
 	controller.isEstablishing = true
 	controller.isEstablishing = true
+	controller.establishStartTime = establishStartTime
 	controller.establishCtx, controller.stopEstablish = context.WithCancel(controller.runCtx)
 	controller.establishCtx, controller.stopEstablish = context.WithCancel(controller.runCtx)
 	controller.establishWaitGroup = new(sync.WaitGroup)
 	controller.establishWaitGroup = new(sync.WaitGroup)
 	controller.candidateServerEntries = make(chan *candidateServerEntry)
 	controller.candidateServerEntries = make(chan *candidateServerEntry)
@@ -1463,6 +1471,7 @@ func (controller *Controller) stopEstablishing() {
 	NoticeInfo("stopped establishing")
 	NoticeInfo("stopped establishing")
 
 
 	controller.isEstablishing = false
 	controller.isEstablishing = false
+	controller.establishStartTime = time.Time{}
 	controller.establishCtx = nil
 	controller.establishCtx = nil
 	controller.stopEstablish = nil
 	controller.stopEstablish = nil
 	controller.establishWaitGroup = nil
 	controller.establishWaitGroup = nil
@@ -1492,13 +1501,9 @@ func (controller *Controller) establishCandidateGenerator() {
 	defer controller.establishWaitGroup.Done()
 	defer controller.establishWaitGroup.Done()
 	defer close(controller.candidateServerEntries)
 	defer close(controller.candidateServerEntries)
 
 
-	// establishStartTime is used to calculate and report the
-	// client's tunnel establishment duration.
-	//
 	// networkWaitDuration is the elapsed time spent waiting
 	// networkWaitDuration is the elapsed time spent waiting
 	// for network connectivity. This duration will be excluded
 	// for network connectivity. This duration will be excluded
 	// from reported tunnel establishment duration.
 	// from reported tunnel establishment duration.
-	establishStartTime := time.Now()
 	var totalNetworkWaitDuration time.Duration
 	var totalNetworkWaitDuration time.Duration
 
 
 	applyServerAffinity, iterator, err := NewServerEntryIterator(controller.config)
 	applyServerAffinity, iterator, err := NewServerEntryIterator(controller.config)
@@ -1598,7 +1603,8 @@ loop:
 
 
 			// adjustedEstablishStartTime is establishStartTime shifted
 			// adjustedEstablishStartTime is establishStartTime shifted
 			// to exclude time spent waiting for network connectivity.
 			// to exclude time spent waiting for network connectivity.
-			adjustedEstablishStartTime := establishStartTime.Add(totalNetworkWaitDuration)
+			adjustedEstablishStartTime := controller.establishStartTime.Add(
+				totalNetworkWaitDuration)
 
 
 			candidate := &candidateServerEntry{
 			candidate := &candidateServerEntry{
 				serverEntry:                serverEntry,
 				serverEntry:                serverEntry,
@@ -1666,7 +1672,7 @@ loop:
 		// case, we're only trying to connect to a specific server entry.
 		// case, we're only trying to connect to a specific server entry.
 
 
 		if (candidateServerEntryCount == 0 ||
 		if (candidateServerEntryCount == 0 ||
-			time.Since(establishStartTime)-totalNetworkWaitDuration > workTime) &&
+			time.Since(controller.establishStartTime)-totalNetworkWaitDuration > workTime) &&
 			controller.config.TargetServerEntry == "" {
 			controller.config.TargetServerEntry == "" {
 
 
 			controller.triggerFetches()
 			controller.triggerFetches()