|  | @@ -74,22 +74,33 @@ static void maybe_initiate_ping(grpc_exec_ctx *exec_ctx,
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_INFLIGHT])) {
 | 
	
		
			
				|  |  |      /* ping already in-flight: wait */
 | 
	
		
			
				|  |  | -    gpr_log(GPR_DEBUG, "already pinging");
 | 
	
		
			
				|  |  | +    if (grpc_http_trace || grpc_bdp_estimator_trace) {
 | 
	
		
			
				|  |  | +      gpr_log(GPR_DEBUG, "Ping delayed [%p]: already pinging", t->peer_string);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      return;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    if (t->ping_state.pings_before_data_required == 0 &&
 | 
	
		
			
				|  |  |        t->ping_policy.max_pings_without_data != 0) {
 | 
	
		
			
				|  |  |      /* need to send something of substance before sending a ping again */
 | 
	
		
			
				|  |  | -    gpr_log(GPR_DEBUG, "too many pings: %d/%d",
 | 
	
		
			
				|  |  | -            t->ping_state.pings_before_data_required,
 | 
	
		
			
				|  |  | -            t->ping_policy.max_pings_without_data);
 | 
	
		
			
				|  |  | +    if (grpc_http_trace || grpc_bdp_estimator_trace) {
 | 
	
		
			
				|  |  | +      gpr_log(GPR_DEBUG, "Ping delayed [%p]: too many recent pings: %d/%d",
 | 
	
		
			
				|  |  | +              t->peer_string, t->ping_state.pings_before_data_required,
 | 
	
		
			
				|  |  | +              t->ping_policy.max_pings_without_data);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      return;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
 | 
	
		
			
				|  |  | -  if (gpr_time_cmp(gpr_time_sub(now, t->ping_state.last_ping_sent_time),
 | 
	
		
			
				|  |  | -                   t->ping_policy.min_time_between_pings) < 0) {
 | 
	
		
			
				|  |  | +  gpr_timespec elapsed = gpr_time_sub(now, t->ping_state.last_ping_sent_time);
 | 
	
		
			
				|  |  | +  /*gpr_log(GPR_DEBUG, "elapsed:%d.%09d min:%d.%09d", (int)elapsed.tv_sec,
 | 
	
		
			
				|  |  | +          elapsed.tv_nsec, (int)t->ping_policy.min_time_between_pings.tv_sec,
 | 
	
		
			
				|  |  | +          (int)t->ping_policy.min_time_between_pings.tv_nsec);*/
 | 
	
		
			
				|  |  | +  if (gpr_time_cmp(elapsed, t->ping_policy.min_time_between_pings) < 0) {
 | 
	
		
			
				|  |  |      /* not enough elapsed time between successive pings */
 | 
	
		
			
				|  |  | -    gpr_log(GPR_DEBUG, "not enough time");
 | 
	
		
			
				|  |  | +    if (grpc_http_trace || grpc_bdp_estimator_trace) {
 | 
	
		
			
				|  |  | +      gpr_log(GPR_DEBUG,
 | 
	
		
			
				|  |  | +              "Ping delayed [%p]: not enough time elapsed since last ping",
 | 
	
		
			
				|  |  | +              t->peer_string);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |      return;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |    /* coalesce equivalent pings into this one */
 | 
	
	
		
			
				|  | @@ -297,20 +308,14 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx,
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  for (size_t i = 0; i < t->ping_ack_count; i++) {
 | 
	
		
			
				|  |  | -    grpc_slice_buffer_add(&t->outbuf,
 | 
	
		
			
				|  |  | -                          grpc_chttp2_ping_create(1, t->ping_acks[i]));
 | 
	
		
			
				|  |  | -  }
 | 
	
		
			
				|  |  | -  t->ping_ack_count = 0;
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  |    /* if the grpc_chttp2_transport is ready to send a window update, do so here
 | 
	
		
			
				|  |  |       also; 3/4 is a magic number that will likely get tuned soon */
 | 
	
		
			
				|  |  |    uint32_t target_incoming_window = GPR_MAX(
 | 
	
		
			
				|  |  |        t->settings[GRPC_SENT_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE],
 | 
	
		
			
				|  |  |        1024);
 | 
	
		
			
				|  |  |    uint32_t threshold_to_send_transport_window_update =
 | 
	
		
			
				|  |  | -      t->outbuf.count > 0 ? target_incoming_window
 | 
	
		
			
				|  |  | -                          : 3 * target_incoming_window / 4;
 | 
	
		
			
				|  |  | +      t->outbuf.count > 0 ? 3 * target_incoming_window / 4
 | 
	
		
			
				|  |  | +                          : target_incoming_window / 2;
 | 
	
		
			
				|  |  |    if (t->incoming_window < threshold_to_send_transport_window_update) {
 | 
	
		
			
				|  |  |      maybe_initiate_ping(exec_ctx, t,
 | 
	
		
			
				|  |  |                          GRPC_CHTTP2_PING_BEFORE_TRANSPORT_WINDOW_UPDATE);
 | 
	
	
		
			
				|  | @@ -324,7 +329,15 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx,
 | 
	
		
			
				|  |  |          t->ping_policy.max_pings_without_data;
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -  maybe_initiate_ping(exec_ctx, t, GRPC_CHTTP2_PING_ON_NEXT_WRITE);
 | 
	
		
			
				|  |  | +  for (size_t i = 0; i < t->ping_ack_count; i++) {
 | 
	
		
			
				|  |  | +    grpc_slice_buffer_add(&t->outbuf,
 | 
	
		
			
				|  |  | +                          grpc_chttp2_ping_create(1, t->ping_acks[i]));
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  t->ping_ack_count = 0;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  if (t->outbuf.count > 0) {
 | 
	
		
			
				|  |  | +    maybe_initiate_ping(exec_ctx, t, GRPC_CHTTP2_PING_ON_NEXT_WRITE);
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    GPR_TIMER_END("grpc_chttp2_begin_write", 0);
 | 
	
		
			
				|  |  |  
 |