<commit_before>package clickhouse

import (
	"net"
	"sync/atomic"
	"time"
)

var tick int32

func dial(network string, hosts []string, r, w time.Duration) (*connect, error) {
	var (
		err error
		abs = func(v int) int {
			if v < 0 {
				return -1
			}
			return v
		}
		conn  net.Conn
		index = abs(int(atomic.AddInt32(&tick, 1)))
	)
	for i := 0; i <= len(hosts); i++ {
		if conn, err = net.DialTimeout(network, hosts[(index+i)%len(hosts)], 2*time.Second); err == nil {
			if tcp, ok := conn.(*net.TCPConn); ok {
				tcp.SetNoDelay(true)
			}
			return &connect{
				Conn:         conn,
				readTimeout:  r,
				writeTimeout: w,
			}, nil
		}
	}
	return nil, err
}

type connect struct {
	net.Conn
	readTimeout  time.Duration
	writeTimeout time.Duration
}

func (conn *connect) Read(b []byte) (int, error) {
	if conn.readTimeout != 0 {
		conn.SetReadDeadline(time.Now().Add(conn.readTimeout))
	}
	return conn.Conn.Read(b)
}
<commit_msg>connect: TCP_NODELAY is impractical for batches<commit_after>package clickhouse

import (
	"net"
	"sync/atomic"
	"time"
)

var tick int32

func dial(network string, hosts []string, r, w time.Duration) (*connect, error) {
	var (
		err error
		abs = func(v int) int {
			if v < 0 {
				return -1
			}
			return v
		}
		conn  net.Conn
		index = abs(int(atomic.AddInt32(&tick, 1)))
	)
	for i := 0; i <= len(hosts); i++ {
		if conn, err = net.DialTimeout(network, hosts[(index+i)%len(hosts)], 2*time.Second); err == nil {
			return &connect{
				Conn:         conn,
				readTimeout:  r,
				writeTimeout: w,
			}, nil
		}
	}
	return nil, err
}

type connect struct {
	net.Conn
	readTimeout  time.Duration
	writeTimeout time.Duration
}

func (conn *connect) Read(b []byte) (int, error) {
	if conn.readTimeout != 0 {
		conn.SetReadDeadline(time.Now().Add(conn.readTimeout))
	}
	return conn.Conn.Read(b)
}

{'fraction_non_alphanumeric': 0.14877384196185287, 'fraction_numerical': 0.010899182561307902, 'mean_word_length': 3.135135135135135, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2514421', 'n_tokens_mistral': 784, 'n_tokens_neox': 693, 'n_words': 181}