Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2629

Connect to multiple mongos in a imbalancing way

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Unknown Unknown
    • None
    • 1.9.1
    • None
    • None

    Description

      Summary

      Connect to multiple mongos in a imbalancing way.

      Let's say I have 3 mongos, a:27017, b:27017 and c:27017. Among them, a:27017 always has the highest CPU utilization since it's first host in the connstring.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      • go.mongodb.org/mongo-driver v1.9.1
      • sharded cluster

      How to Reproduce

      Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

      This is how I connect to MongoDB.

      package main
       
      import (
      	"context"
       
      	"go.mongodb.org/mongo-driver/mongo"
      	"go.mongodb.org/mongo-driver/mongo/options"
      	"go.mongodb.org/mongo-driver/mongo/readpref"
      	"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
      )
       
      const url = "mongodb://user:passwd@a:27017,b:b:27017,c:27017/db?maxPoolSize=20"
       
      func main() {
      	cs, err := connstring.ParseAndValidate(url)
      	if err != nil {
      		panic(err)
      	}
       
      	mode, _ := readpref.ModeFromString(cs.ReadPreference)
      	readPref, err := readpref.New(mode)
      	if err != nil {
      		panic(err)
      	}
       
      	option := options.Client().
      		ApplyURI(url).
      		SetAppName(cs.AppName).
      		SetReadPreference(readPref).
      		SetMaxPoolSize(cs.MaxPoolSize)
       
      	client, err := mongo.Connect(context.Background(), option)
      	if err != nil {
      		panic(err)
      	}
      }
      

      Additional Background

      Please provide any additional background information that may be helpful in diagnosing the bug.

      These mongos are StatefulSets in K8s, 6 equal pods.
       

      Attachments

        Activity

          People

            benji.rewis@mongodb.com Benji Rewis (Inactive)
            ken8203@gmail.com Jay Chung
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: