Why document db is creating 3 connections for a single insert operation.

0

Hello, I have created a document db instance of t4g.medium size. I am trying to insert data in a collection. While monitoring the connection count in AWS monitor console, I observed that for every request 3 connections are getting created. Has anybody faced any similar issue or any idea why 3 connections are getting created for each request.

Connection code

``

func createConnection() (*mongo.Client, error) {
	clusterEndpoint := fmt.Sprintf("%v:%v", host, port)
	connectionURI := fmt.Sprintf(ConnectionStringTemplate, username, password, clusterEndpoint, database, ReadPreference)
	tlsConfig, err := getCustomTLSConfig(CaFilePath)
	if err != nil {
		log.Errorf(context.Background(), "Failed getting TLS configuration: %v", err)
	}
	clientOptions := options.Client().ApplyURI(connectionURI).SetTLSConfig(tlsConfig)
	clientOptions = clientOptions.SetMaxPoolSize(1)
	clientOptions = clientOptions.SetMinPoolSize(1)

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()

	client, err := mongo.Connect(ctx, clientOptions)
	if err != nil {
		return nil, err
	}

	// Test the connection
	err = client.Ping(ctx, nil)
	if err != nil {
		return nil, err
	}
	log.Infof(context.Background(), "Connection created successfully")

	return client, nil
}

``

AWS Monitor Screenshot :

질문됨 일 년 전279회 조회
1개 답변
0

This is the behavior of the Go driver (is not the only one, PyMongo does the same), which opens two additional sockets per instance for monitoring the server's state. See the details here.

You could try settings like heartbeatFrequencyMS to minimize those background server checks or directConnection to connect only to one instance specified in the URI (if you are going to use only single instance cluster and not connect in replica set mode).

AWS
Mihai A
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠