WebFulx和Redis的反應式API性能矩陣react
·使用SpringBoot 2.0,WebFlux和Reactive Redis構建一組徹底無阻塞的REST API。web
·針對傳統的非活動API對上述Reactive API進行性能測試redis
· spring-boot-starter-web spring
· spring-boot-starter-data-redis docker
· spring-webflux 數據庫
· spring-boot-starter-data-redis-reactive apache
·添加/更新客戶bash
· findById併發
@RestController@RequestMapping("/customers/rx")public class CustomerControllerRx { @Autowired private ReactiveRedisTemplate<String, Customer> redisTemplate; private ReactiveValueOperations<String, Customer> reactiveValueOps; @PostMapping public Mono<Boolean> add(@RequestBody Customer customer) { reactiveValueOps = redisTemplate.opsForValue(); Mono<Boolean> result = reactiveValueOps.set(customer.getExternalId(), customer);
return result; } @GetMapping("/{id}") public Mono<Customer> findById(@PathVariable("id") String id) { reactiveValueOps = redisTemplate.opsForValue(); Mono<Customer> fetchedAccount = reactiveValueOps.get(id); return fetchedAccount; }}複製代碼
ReactiveRedisTemplate在RedisConfigRx中配置app
@RestController@RequestMapping("/customers")public class CustomerController { @Autowired CustomerRepository repository; @PostMapping public Customer add(@RequestBody Customer customer) { return repository.save(customer); } @GetMapping("/{externalId}") public Customer findById(@PathVariable("externalId") String externalId) { Customer optCustomer = repository.findByExternalId(externalId); if (Optional.ofNullable(optCustomer).isPresent()) return optCustomer; else{ return null; } }}// Code for CustomerRepositorypublic interface CustomerRepository extends CrudRepository<Customer, Long> { Customer findByExternalId(String externalId); List<Customer> findByAccountsId(Long id);}複製代碼
· Redis不正式支持Windows。可是,在UNIX或Windows啓動和運行Redis的最簡單方法是使用Docker。
·使用如下步驟從docker hub中提取redis映像,並在分離模式下從端口6379開始。
· $ docker pull redis · $ docker run -d -p 6379:6379 --name redis1 redis· $ docker ps -a //確保redis啓動並運行。複製代碼
·安裝Apache JMeter,https://jmeter.apache.org/
·從插件下載站點https://jmeter-plugins.org/安裝如下圖形插件
o基本圖表
o附加圖表
jmeter -n -t <TestPLan.jmx> -l <TestPlan.jtl> -e -o <output folder>複製代碼
-n在非GUI模式下運行
-t提供測試文件的名稱
-l輸出報告文件的名稱
-e jMeter遵循jmx文件中指定的後處理。
-o儀表板文件夾。
·經過鏈接到Docker上的Redis DB,確保應用程序啓動時沒有錯誤。
·爲測試計劃設置用戶(線程)和循環(迭代)。
使用JMeter UI打開TestPlan並更改用戶(線程)數並設置循環次數,保存測試計劃,退出JMeter UI。
·執行測試計劃
轉到JMeter \ bin文件夾並執行:
jmeter - n - t < path > \ SaveCustomers。jmx - l < path > \ SaveCustomers.JTL - e - o < path > \ SaveCustomersOutput - 5U sers複製代碼
本人創業團隊產品MadPecker,主要作BUG管理、測試管理、應用分發
網址:www.madpecker.com,有須要的朋友歡迎試用、體驗!
本文爲MadPecker團隊譯製,轉載請標明出處