欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于dubbo的RPC和RESTful性能及對(duì)比

 更新時(shí)間:2022年12月19日 10:04:44   作者:fomeiherz  
這篇文章主要介紹了關(guān)于dubbo的RPC和RESTful性能及對(duì)比,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

先上結(jié)論

RPC請(qǐng)求的效率是HTTP請(qǐng)求的1.6倍左右,性能明顯比HTTP請(qǐng)求要高很多。

原因分析

RESTful是基于HTTP協(xié)議進(jìn)行交互的,HTTP協(xié)議包含大量的請(qǐng)求頭、響應(yīng)頭信息。

而dubbo是基于dubbo自定義的二進(jìn)制協(xié)議進(jìn)行傳輸,消息體比較簡(jiǎn)單,傳輸數(shù)據(jù)要小很多。

性能對(duì)比

HTTP請(qǐng)求代碼

// 服務(wù)端基于spring boot搭建
// 服務(wù)端代碼
@SpringBootApplication
@RestController
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @RequestMapping("/helloworld")
    public String helloworld() {
        return "hello world";
    }

}

// 客戶端代碼
import org.springframework.util.StopWatch;
import org.springframework.web.client.RestTemplate;

public class HelloworldTest {
    public static void main(String[] args) {
        RestTemplate restTemplate = new RestTemplate();
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        for (int j = 0; j < 10; j++) {
            System.out.println("------------------");
            for (int i = 1; i <= 10000; i++) {
                restTemplate.getForObject("http://127.0.0.1/helloworld", String.class);
                if (i % 1000 == 0) {
                    stopWatch.stop();
                    System.out.println(stopWatch.getTotalTimeSeconds());
                    stopWatch = new StopWatch();
                    stopWatch.start();
                }
            }
        }
    }
}

RPC代碼

// dubbo-demo工程的代碼,詳情請(qǐng)看:https://github.com/apache/dubbo/tree/master/dubbo-demo
// 服務(wù)端
public class DemoServiceImpl implements DemoService {

    @Override
    public String sayHello(String name) {
        return "Hello " + name + ", response from provider: " + RpcContext.getContext().getLocalAddress();
    }
}

// 客戶端
public class Consumer {

    public static void main(String[] args) {
        //Prevent to get IPV6 address,this way only work in debug mode
        //But you can pass use -Djava.net.preferIPv4Stack=true,then it work well whether in debug mode or not
        System.setProperty("java.net.preferIPv4Stack", "true");
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-consumer.xml"});
        context.start();
        DemoService demoService = (DemoService) context.getBean("demoService"); // get remote service proxy

        StopWatch stopWatch = new StopWatch();
        stopWatch.start();

        for (int j = 0; j < 10; j++) {
            System.out.println("-----------");
            for (int i = 1; i <= 10000; i++) {
                demoService.sayHello("world"); // call remote method
                if (i % 1000 == 0) {
                    stopWatch.stop();
                    System.out.println(stopWatch.getTotalTimeSeconds());
                    stopWatch = new StopWatch();
                    stopWatch.start();
                }
            }
        }
    }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java延遲隊(duì)列DelayQueue原理詳解

    Java延遲隊(duì)列DelayQueue原理詳解

    這篇文章主要介紹了Java延遲隊(duì)列DelayQueue原理詳解,DelayQueue 是一個(gè)通過(guò)PriorityBlockingQueue實(shí)現(xiàn)延遲獲取元素的無(wú)界隊(duì)列無(wú)界阻塞隊(duì)列,其中添加進(jìn)該隊(duì)列的元素必須實(shí)現(xiàn)Delayed接口,而且只有在延遲期滿后才能從中提取元素,需要的朋友可以參考下
    2023-12-12
  • Java排序算法總結(jié)之堆排序

    Java排序算法總結(jié)之堆排序

    這篇文章主要介紹了Java排序算法總結(jié)之堆排序,詳細(xì)分析了堆排序的原理與java實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2015-05-05
  • Java中JSON字符串與java對(duì)象的互換實(shí)例詳解

    Java中JSON字符串與java對(duì)象的互換實(shí)例詳解

    這篇文章主要介紹了在java中,JSON字符串與java對(duì)象的相互轉(zhuǎn)換實(shí)例詳解,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-08-08
  • SpringBoot整合阿里云OSS對(duì)象存儲(chǔ)服務(wù)的實(shí)現(xiàn)

    SpringBoot整合阿里云OSS對(duì)象存儲(chǔ)服務(wù)的實(shí)現(xiàn)

    這篇文章主要介紹了SpringBoot整合阿里云OSS對(duì)象存儲(chǔ)服務(wù)的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • mybatis對(duì)象List<String> List<Integer>屬性映射方式

    mybatis對(duì)象List<String> List<Integer>屬性映射方式

    這篇文章主要介紹了mybatis對(duì)象List<String> List<Integer>屬性映射方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-12-12
  • java常用工具類 XML工具類、數(shù)據(jù)驗(yàn)證工具類

    java常用工具類 XML工具類、數(shù)據(jù)驗(yàn)證工具類

    這篇文章主要為大家詳細(xì)介紹了java常用工具類,包括XML工具類、數(shù)據(jù)驗(yàn)證工具類,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • 使用自定義注解實(shí)現(xiàn)redisson分布式鎖

    使用自定義注解實(shí)現(xiàn)redisson分布式鎖

    這篇文章主要介紹了使用自定義注解實(shí)現(xiàn)redisson分布式鎖,具有很好的參考價(jià)值,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • spring boot 防止重復(fù)提交實(shí)現(xiàn)方法詳解

    spring boot 防止重復(fù)提交實(shí)現(xiàn)方法詳解

    這篇文章主要介紹了spring boot 防止重復(fù)提交實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了spring boot 防止重復(fù)提交具體配置、實(shí)現(xiàn)方法及操作注意事項(xiàng),需要的朋友可以參考下
    2019-11-11
  • Mybatis-Plus最優(yōu)化持久層開發(fā)過(guò)程

    Mybatis-Plus最優(yōu)化持久層開發(fā)過(guò)程

    Mybatis-plus(簡(jiǎn)稱MP)是一個(gè)Mybatis的增強(qiáng)工具,在mybatis的基礎(chǔ)上只做增強(qiáng)不做改變,提高效率,自動(dòng)生成單表的CRUD功能,這篇文章主要介紹了Mybatis-Plus最優(yōu)化持久層開發(fā),需要的朋友可以參考下
    2024-07-07
  • Java如何Mock FileInputStream問(wèn)題

    Java如何Mock FileInputStream問(wèn)題

    這篇文章主要介紹了Java如何Mock FileInputStream問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-09-09

最新評(píng)論