<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 負載策略 通過xorm.NewEngineGroup創建EngineGroup時,第三個參數為policies,我們可以通過該參數來指定Slave訪問的負載策略。如創建EngineGroup時未指定,則默認使用輪詢的負載策略。 xorm中內置五種負載策略,分別為隨機訪問負載策略,權重隨機訪問負載策略,輪詢訪問負載策略,權重輪詢訪問負載策略和最小連接數訪問負載策略。開發者也可以通過實現GroupPolicy接口,來實現自定義負載策略。 1. 隨機訪問負載策略 ~~~ import ( _ "github.com/lib/pq" "github.com/xormplus/xorm" ) var eg *xorm.EngineGroup func main() { conns := []string{ "postgres://postgres:root@localhost:5432/test?sslmode=disable;", "postgres://postgres:root@localhost:5432/test1?sslmode=disable;", "postgres://postgres:root@localhost:5432/test2?sslmode=disable", } var err error eg, err = xorm.NewEngineGroup("postgres", conns, xorm.RandomPolicy()) } ~~~ 2. 權重隨機訪問負載策略 ~~~ import ( _ "github.com/lib/pq" "github.com/xormplus/xorm" ) var eg *xorm.EngineGroup func main() { conns := []string{ "postgres://postgres:root@localhost:5432/test?sslmode=disable;", "postgres://postgres:root@localhost:5432/test1?sslmode=disable;", "postgres://postgres:root@localhost:5432/test2?sslmode=disable", } var err error //此時設置的test1數據庫和test2數據庫的隨機訪問權重為2和3 eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRandomPolicy([]int{2, 3})) } ~~~ 3. 輪詢訪問負載策略 ~~~ import ( _ "github.com/lib/pq" "github.com/xormplus/xorm" ) var eg *xorm.EngineGroup func main() { conns := []string{ "postgres://postgres:root@localhost:5432/test?sslmode=disable;", "postgres://postgres:root@localhost:5432/test1?sslmode=disable;", "postgres://postgres:root@localhost:5432/test2?sslmode=disable", } var err error eg, err = xorm.NewEngineGroup("postgres", conns, xorm.RoundRobinPolicy()) } ~~~ 4. 權重輪詢訪問負載策略 ~~~ import ( _ "github.com/lib/pq" "github.com/xormplus/xorm" ) var eg *xorm.EngineGroup func main() { conns := []string{ "postgres://postgres:root@localhost:5432/test?sslmode=disable;", "postgres://postgres:root@localhost:5432/test1?sslmode=disable;", "postgres://postgres:root@localhost:5432/test2?sslmode=disable", } var err error //此時設置的test1數據庫和test2數據庫的輪詢訪問權重為2和3 eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRoundRobinPolicy([]int{2, 3})) } ~~~ 5. 最小連接數訪問負載策略 ~~~ import ( _ "github.com/lib/pq" "github.com/xormplus/xorm" ) var eg *xorm.EngineGroup func main() { conns := []string{ "postgres://postgres:root@localhost:5432/test?sslmode=disable;", "postgres://postgres:root@localhost:5432/test1?sslmode=disable;", "postgres://postgres:root@localhost:5432/test2?sslmode=disable", } var err error eg, err = xorm.NewEngineGroup("postgres", conns, xorm.LeastConnPolicy()) } ~~~ 6. 自定義負載策略 實現GroupPolicy接口來實現自定義負載策略。 ~~~ type GroupPolicy interface { Slave(*EngineGroup) *Engine } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看