Giter VIP home page Giter VIP logo

sofa-rpc's Introduction

SOFARPC

Build Status Coverage Status License Maven Percentage of issues still open Open in CodeBlitz

Overview

SOFARPC is a high-performance, high-extensibility, production-level Java RPC framework. In Ant Financial, SOFARPC has been used for more than ten years and developing for five generations. SOFARPC is dedicated to simplify RPC calls between applications, and provide convenient, no code intrusion, stable, and efficient point-to-point remote service invocation solutions for applications. For user and developer easy to improve features, SOFARPC provides a wealth of model abstraction and extensible interfaces, including filter, routing, load balancing, and so on. At the same time, it provides a rich MicroService governance solution around the SOFARPC framework and its surrounding components.

SOFARPC Architecture

Features

  • No code intrusion, high-performance remote service call
  • Supports multiple service routing and load balancing policies
  • Supports multiple service registries
  • Supports multiple protocols
  • Supports multiple invoke type, such as synchronous, oneway, callback, generalized and more.
  • Support cluster failover, service warm-up, automatic fault tolerance
  • High extensibility for easy to improve features as needed

Related Projects

Requirements

Build-time requirement: JDK 8 or above and Maven 3.2.5 or above.

Runtime requirement: JDK 8 or above.

Documents

Contribution

How to Contributing

Contact Us

  • DingTalk Group

    DingTalk

License

SOFARPC is licensed under the Apache License 2.0, and SOFARPC uses some third-party components, you can view their open source license here NOTICE.

sofa-rpc's People

Contributors

alaneuler avatar chuailiwu avatar dependabot[bot] avatar evenljj avatar glmapper avatar hqq2023623 avatar jervyshi avatar jjtyro avatar jwx0925 avatar khotyn avatar leizhiyuan avatar leyou240 avatar liangyuanpeng avatar lo1nt avatar mingjunduan avatar negnail avatar nobodyiam avatar oldratlee avatar orezzero avatar qilongzhang avatar rickey17 avatar scienjus avatar stenicholas avatar taobaorun avatar ujjboy avatar wangchengming666 avatar xuqiu avatar zhaojigang avatar zhenjunma avatar zonghaishang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sofa-rpc's Issues

NPE when invoke asynchronously use JdkProxy.

It will throw NPE when invoke asynchronously use JDKProxy. the demo case like this:

public interface AllTypeService {
    public int echoInt(int i);
}
ConsumerConfig<AllTypeService> aConsumer = new ConsumerConfig<AllTypeService>()
       .setInterfaceId(AllTypeService.class.getName())
       .setProxy("jdk")
       .setInvokeType(RpcConstants.INVOKER_TYPE_FUTURE)
AllTypeService helloService2 = aConsumer.refer();
helloService2.echoInt(1); // will throw NPE 

The reason for this bug is appResponse of SofaResponse is null when async invoke. We need set default return value when the return type is primitive class.

PS: JavassistProxy is ok.

wiki

Typo

Improve

请问后面会提供SofaRPC代码层的启动链/调用链流程图么。像Dubbo那样更能让开发者有全局的印象。

获取预热权重算法对比疑惑

您好,获取预热权重是根据AbstractLoadBalancer类的int getWeight(providerInfo)方法从provider中或得到相关权重(默认值100),对比Dubbo目前预热权重的算法来说,代码如下:

protected int getWeight(Invoker<?> invoker, Invocation invocation) {
        int weight = invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.WEIGHT_KEY, Constants.DEFAULT_WEIGHT);
        if (weight > 0) {
            long timestamp = invoker.getUrl().getParameter(Constants.REMOTE_TIMESTAMP_KEY, 0L);
            if (timestamp > 0L) {
                int uptime = (int) (System.currentTimeMillis() - timestamp);
                int warmup = invoker.getUrl().getParameter(Constants.WARMUP_KEY, Constants.DEFAULT_WARMUP);
                if (uptime > 0 && uptime < warmup) {
                    weight = calculateWarmupWeight(uptime, warmup, weight);
                }
            }
        }
        return weight;
    }
static int calculateWarmupWeight(int uptime, int warmup, int weight) {
        int ww = (int) ((float) uptime / ((float) warmup / (float) weight));
        return ww < 1 ? 1 : (ww > weight ? weight : ww);
    }

是不是按照Provider启动时间增长逐渐放量提高权重直到Weight的算法效果更佳?另外,服务预热时间能否按照Provider启动时间动态调整设置,因为此处没有比较官方推荐的预热时间,也不太好推荐毕竟每个接入的系统情况不一样,所以能做成动态调整设置而不是自己预估一个可接受的范围去设置?

Can you support the component

Micro service R & D framework, RPC framework, service registry, distributed timing task, flow limiting / fusing framework, dynamic configuration push, distributed link tracking, Metrics monitoring and measurement, distributed high availability message queue, distributed transaction framework, distributed database agent layer

使用指定版本的spring boot,出现异常

指定spring boot版本为 1.5.12.RELEASE ,sofaboot为2.3.1 ,异常如下:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-04-27 16:55:55.978 ERROR 28116 --- [ main] o.s.boot.SpringApplication : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'readinessCheck' defined in class path resource [com/alipay/sofa/healthcheck/service/EndPointConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alipay.sofa.healthcheck.service.SofaBootReadinessCheckEndpoint]: Factory method 'readinessCheck' threw exception; nested exception is java.lang.IllegalArgumentException: Id must only contains letters, numbers and ''
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1128) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1022) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:754) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at com.test.Tet.main(Tet.java:14) [classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) [idea_rt.jar:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.alipay.sofa.healthcheck.service.SofaBootReadinessCheckEndpoint]: Factory method 'readinessCheck' threw exception; nested exception is java.lang.IllegalArgumentException: Id must only contains letters, numbers and '
'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
... 23 common frames omitted
Caused by: java.lang.IllegalArgumentException: Id must only contains letters, numbers and '_'
at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.boot.actuate.endpoint.AbstractEndpoint.setId(AbstractEndpoint.java:104) ~[spring-boot-actuator-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at org.springframework.boot.actuate.endpoint.AbstractEndpoint.(AbstractEndpoint.java:72) ~[spring-boot-actuator-1.5.12.RELEASE.jar:1.5.12.RELEASE]
at com.alipay.sofa.healthcheck.service.SofaBootReadinessCheckEndpoint.(SofaBootReadinessCheckEndpoint.java:44) ~[healthcheck-sofa-boot-starter-2.3.1.jar:2.3.1]
at com.alipay.sofa.healthcheck.service.EndPointConfig.readinessCheck(EndPointConfig.java:34) ~[healthcheck-sofa-boot-starter-2.3.1.jar:2.3.1]
at com.alipay.sofa.healthcheck.service.EndPointConfig$$EnhancerBySpringCGLIB$$a9497e54.CGLIB$readinessCheck$0() ~[healthcheck-sofa-boot-starter-2.3.1.jar:2.3.1]
at com.alipay.sofa.healthcheck.service.EndPointConfig$$EnhancerBySpringCGLIB$$a9497e54$$FastClassBySpringCGLIB$$4bf76371.invoke() ~[healthcheck-sofa-boot-starter-2.3.1.jar:2.3.1]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.16.RELEASE.jar:4.3.16.RELEASE]
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356) ~[spring-context-4.3.4.RELEASE.jar:4.3.4.RELEASE]
at com.alipay.sofa.healthcheck.service.EndPointConfig$$EnhancerBySpringCGLIB$$a9497e54.readinessCheck() ~[healthcheck-sofa-boot-starter-2.3.1.jar:2.3.1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_91]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_91]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_91]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_91]
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.3.4.RELEASE.jar:4.3.4.RELEASE]
... 24 common frames omitted

2018-04-27 16:55:56.085 INFO 28116 --- [ain-EventThread] org.apache.zookeeper.ClientCnxn : EventThread shut down
2018-04-27 16:55:56.085 INFO 28116 --- [PC-ShutdownHook] org.apache.zookeeper.ZooKeeper : Session: 0x163052a1ee30018 closed

Default bootstrap of consumer side.

The default bootstrap is bolt now, if we use the other protocol, we must specified bootstrap like code below:

consumerConfig.setProtocol("http").setBootstrap("http");

It is not friendly. I will do some refactor:

  • Change default bootstrap extension to sofa (com.alipay.sofa.rpc.bootstrap.DefaultProviderBootstrap and com.alipay.sofa.rpc.bootstrap.DefaultConsumerBootstrap)
  • Use protocol as bootstrap name If the bootstrap of consumer is not specified. If not exist extension named it, then use default bootstrap.

Build fail in sonar.

When running findbug plugin of sonar:

mvn clean package -DskipTests=true org.codehaus.mojo:sonar-maven-plugin:2.6:sonar \
-Dsonar.sensor.inclusions=JavaSourceImporter,JavaSquidSensor,CpdSensor,FindbugsSensor,ProfileSensor \
-Dsonar.dynamicAnalysis=reuseReports \
-Dsonar.branch=dev_1.0 \
-Dsonar.host.url=http://xxx:9000/ \
-Dsonar.host.username=xxx \
-Dsonar.host.password=xxx \
-Dsonar.jdbc.url='jdbc:mysql://xxxx:3306/sonar?useUnicode=true&characterEncoding=utf8' \
-Dsonar.jdbc.username=mysql \
-Dsonar.jdbc.password=xx_mysql \
-Dsonar.sourceEncoding=UTF-8

It 's will build fail, and the exception like this:

[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven-plugin:2.6:sonar (default-cli) on project xxx-parent: Can not execute SonarQube analysis: Unable to determine structure of project. Probably you use Maven Advanced Reactor Options, which is not supported by SonarQube and should not be used. -> [Help 1]

The cache of method is scattered in different class.

There are multiple classes for storing caches of method:

  • com.alipay.sofa.rpc.common.utils.ReflectUtils#METHOD_CACHE
  • com.alipay.sofa.rpc.common.utils.ReflectUtils#METHOD_ARGS_TYPE_CACHE
  • com.alipay.sofa.rpc.common.ReflectCache#METHOD_CACHE

Need to aggregate to one class.

We will move all caches to ReflectCache:

  • interfaceName+methodName -> Method for not overload method, such as http, protobuf.
  • interfaceName+methodName -> MethodArgTypes for not overload method, such as http, protobuf.
  • interfaceName+methodName+methodArgStrs -> Method for overload method, such as bolt.

Support gRPC.

对grpc 的支持.

1.sofa-rpc 支持 grpc
2.starter 项目做 grpc 的 xml 转换等.

有问题随时沟通.

Support elastic connection holder like connection pool of datasource.

The default connection holder of SOFARPC is AllConnectConnectionHolder. It means the service consumer will connect to all service provider.

If the service provider has a lot of nodes, it will take a long time to establish all connections.

We hope to implement a ConnectionHolder like connection pool of data source. For example, if there are 100 providers, we can start to invoke after initial connections (such as 20 providers) have been established, and build the other 80 connections asynchronously and parallelly.

Wrong exit code of check_format.sh

When travis-ci build failing because of check_format.sh, the result like this:

$ sh ./check_format.sh
Please commit your change before run this shell, un commit files:
 M xxx
./check_format.sh: 11: exit: Illegal number: -1

自动故障剔除降级恢复策略疑惑

您好,关于自动故障剔除功能降级恢复策略,目前主要的降级策略就是权重降级策略即WeightDegradeStrategy类,也就是根据自定义配置的weightDegradeRate来调整Provider的权重
// degrade weight of this provider info
boolean success = ProviderInfoWeightManager.degradeWeight(providerInfo, degradeWeight);
除此之外还有别的降级策略比如说返回常量值,抛出指定异常等等吗?降级策略可以自定义配置吗?
另外,SOFARPC的恢复策略即权重恢复策略WeightRecoverStrategy类也就是如下代码处理:
int recoverWeight = CalculateUtils.multiply(currentWeight, weightRecoverRate);
int originWeight = statDimension.getOriginWeight();
// recover weight of this provider info
if (recoverWeight >= originWeight) {
measureResultDetail.setRecoveredOriginWeight(true);
ProviderInfoWeightManager.recoverOriginWeight(providerInfo, originWeight);
直接根据配置的weightRecoverRate恢复比率参数来更新Provider的权重,这边能按照阶梯式的恢复比率逐渐放量恢复而不是自定义配置恢复比率呢?

预热权重的算法的疑问?

你好,关于预热权重的功能,我有个疑问,我看的是 RandomLoadBalancer 类,该类的 doSelect 方法会判断如果服务列表中的权重不同,会进行一个选择,即第二个 if 块的代码。

  if (totalWeight > 0 && !isWeightSame) {
        // 如果权重不相同且权重大于0则按总权重数随机
        int offset = random.nextInt(totalWeight);
        // 并确定随机值落在哪个片断上
        for (int i = 0; i < size; i++) {
            offset -= getWeight(providerInfos.get(i));
            if (offset < 0) {
                providerInfo = providerInfos.get(i);
                break;
            }
        }
    }

我推导了一下:

假设有 A, B, C, 3 个服务,每个服务默认权重 100,其中 C 现在处于预热阶段,则 C 的权重等于 10.

那么总权重 210。

随机一个数,
假设是 199,那么当这个算法运行结束,C,永远不会被选择到;
假设这个随机数是 200,那么当这个算法运行结束,极有可能会击中 C(C 在最后一位,即集合的排序是倒序)。但如果 C 在第二位或者第一位,那么,C 就不会被击中。这样是不是不够公平?

并且我好像没有从代码中看到对服务列表进行倒序。

还请您解答!谢谢!

`version` will no longer be used as one of the keywords.

The version field in provider config or consumer config now is a keyword of the service name. The other two keywords are interface and uniqueId.

Now, version is only used for compatible with bolt and dubbo, and no used in HTTP, REST and others, so we can no longer be used version as a default keyword, and mark it as @Deprecated.

If some guys need to publish different implements of one interface, they can use uniqueId.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.