Lihuanghe / SMSGate

这是一个在netty4框架下实现的三网合一短信网关核心框架,支持(cmpp/smpp3.4/sgip1.2/smgp3) 短信协议解析,支持长短信合并和拆分,也支持wap短信和闪信。
Apache License 2.0
913 stars 454 forks source link

有关cmpp速度问题 #14

Closed GithubRyze closed 5 years ago

GithubRyze commented 5 years ago

黄工你好,我们在使用过程中,在局域网能接收的速度还是很快,但是把服务器放到阿里云上面后,变的超级慢?请问下是否cmpp参数没有设置正确?以下是服务端代码, public static void start() throws Exception {

    ResourceLeakDetector.setLevel(Level.ADVANCED);
    final EndpointManager manager = EndpointManager.INS;

    CMPPServerEndpointEntity server = new SohanCMPPServerEndpointEntity();
    server.setId(SERVER_ID);
    server.setHost("0.0.0.0");
    SohanConfig config = ApplicationContextUtil.getBean(SohanConfig.class);
    String port = config.getCmppServerRecivePort();
    if (StringUtils.isEmpty(port))
    {
        server.setPort(7890);
    } else
    {
        server.setPort(Integer.valueOf(port));
    }
    server.setValid(true);
    // 使用ssl加密数据流
    server.setUseSSL(false);

    manager.openEndpoint(server);
    manager.startConnectionCheckTask();

}

/*
 * 创建自己扩展的Entity
 */
private static class SohanCMPPServerEndpointEntity
        extends CMPPServerEndpointEntity
{

    @Override
    public EndpointEntity getChild(String userName)
    {

        SohanConfig config = ApplicationContextUtil.getBean(SohanConfig.class);
        // 如果当前是模拟环境,则进行模拟登录即可。模拟登录密码默认都是123456
        if(config.isSimulation()) {
            EndpointEntity child = simulationLogin(userName);
            super.addchild(child);
            return child;
        }
        // 依赖业务服务器的登录判断
        GrpcCmppService handler = ApplicationContextUtil
                .getBean(GrpcCmppService.class);
        LoginResponse resp = handler.loginBlocking(
                LoginRequest.newBuilder().setUserName(userName).build());
        if (resp != null)
        {
            SohanCMPPServerChildEndpointEntity child = new SohanCMPPServerChildEndpointEntity();
            child.setId(resp.getCmppSpId());
            child.setChartset(Charset.forName("utf-8"));
            child.setGroupName("test");
            child.setUserName(resp.getCmppSpId());
            child.setUser(resp);

            try
            {
                child.setPassword(AESUtil.decrypt2Str(
                        resp.getCmppPwd(), AESUtil.aesKey));
            } catch (Exception e)
            {
                log.error("密码错误,账号:{}", resp.getCmppSpId());

// e.printStackTrace(); }

            child.setValid(true);
            child.setVersion((short) 0x20);

            child.setMaxChannels((short) 12);
            child.setRetryWaitTimeSec((short) 30);
            child.setMaxRetryCnt((short) 3);
            child.setReSendFailMsg(false);
            // 服务器的写,通常都是回执和上行短信,此时不限速,越快越好
            // child.setWriteLimit(1500);
            child.setReadLimit(3000);
            List<BusinessHandlerInterface> serverhandlers = new ArrayList<BusinessHandlerInterface>();
            serverhandlers.add(new MessageReceiveHandler());
            child.setBusinessHandlerSet(serverhandlers);
            return child;
        }
        return null;
    }
}
能否帮我抽空看下,在局域网内能接收很多,一上阿里云一直没有超过 30/s, 谢谢!
Lihuanghe commented 5 years ago

应该是网络时延的问题,在局域网一个请求收发可能1ms都不到,但阿里云估计得几十了。你的测试代码应该是发一个请求,等待收到response后,再发下一个。提高速度方法有异步发送,或者多个线程并发发送。