很多连接都处于等待和关闭阶段

I am using gorilla/mux framework for a rest api which inserts data into cassandra. When I run performance test on the api with jmeter and 2500 users , i get error of socket exception after 1500 active users . When i checked the connection status, lots of connections are in time wait/closed stage while number of established connections are very low .

enter image description here

But when i set keepalive enabled in jmeter , there are no connections in timewait /closed stage and I get no errors

Keeping keep alive in jmeter is not my real scenario . How can i set keep alive through framework itself?