zoukankan      html  css  js  c++  java
  • go xorm,负载均衡

    创建引擎组时,我们可以指示特殊的负载平衡策略。xorm上有5个负载平衡。它们是RandomPolicyWeightRandomPolicyRoundRobinPolicyWeightRoundRobinPolicyLeastConnPolicy您还可以根据GroupPolicy界面实施自己的策略

    • 随机政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/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())
    }
    
    • 权重随机政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/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
    	// set the weights
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRandomPolicy([]int{2, 3}))
    }
    
    • RoundRobinPolicy
    import (
        _ "github.com/lib/pq"
        "xorm.io/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())
    }
    
    • WeightRoundRobinPolicy
    import (
        _ "github.com/lib/pq"
        "xorm.io/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
        // set the weights
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRoundRobinPolicy([]int{2, 3}))
    }
    
    • 最低Conn政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/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())
    }
  • 相关阅读:
    ORA-01861: 文字与格式字符串不匹配
    Tomcat启动失败Unrecognized Windows Sockets error: 0: JVM_Bind
    登陆数据库,界面一直保持正在登陆的状态,oracle使用界面无法登陆
    java.sql.SQLException: 关闭的连接
    如何提高家庭宽带的网速?
    打爆IPv4的不一定是IPv6,可能是中国互联网!
    LibreOffice 7.0.1 发布,开源办公套件
    iPhone12系列售价曝光
    TikTok正式起诉特朗普政府
    WordPress主题ripro 6.6
  • 原文地址:https://www.cnblogs.com/yangxinpython/p/12717964.html
Copyright © 2011-2022 走看看