(dialer *net.Dialer)
| 42 | } |
| 43 | |
| 44 | func newDialRateLimiter(dialer *net.Dialer) *dialRateLimiter { |
| 45 | // exact value doesn't matter too much, but too low will be too slow, |
| 46 | // and too high will reduce the beneficial effect on thread count |
| 47 | const concurrentDialsPerCpu = 10 |
| 48 | |
| 49 | return &dialRateLimiter{ |
| 50 | dialer: dialer, |
| 51 | sem: make(chan struct{}, concurrentDialsPerCpu*runtime.NumCPU()), |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func (d *dialRateLimiter) DialContext(ctx context.Context, network, address string) (net.Conn, error) { |
| 56 | d.sem <- struct{}{} |