github.com/nyan233/littlerpc@v0.4.6-0.20230316182519-0c8d5c48abaf/gen_graph.py (about)

     1  import numpy as np
     2  import matplotlib.pyplot as plt
     3  import sys
     4  
     5  pubilc_x = [100, 500, 2000, 5000]
     6  line_color = {
     7      "grpc": "yellow",
     8      "arpc": "red",
     9      "rpcx": "blue",
    10      "kitex": "black",
    11      "net/rpc": "green",
    12      "lrpc": "pink"
    13  }
    14  
    15  
    16  def print_graph(data_map: dict, tittle: str, style: str) -> None:
    17      # plt.subplots_adjust(hspace=0.30)
    18      fig, avs = plt.subplots(2, 2)
    19      fig.subplots_adjust(hspace=0.07)
    20      fig.suptitle(tittle)
    21      layout = ["tps", "p99_latency", "mean_latency", "max_latency"]
    22      for k, v in enumerate(layout):
    23          if k == 0:
    24              gen_sub_graph(avs[0, 0], data_map, style, "tps", "Concurrent Clients", "Thoughts(TPS)")
    25          elif k == 1:
    26              gen_sub_graph(avs[0, 1], data_map, style, "p99_latency", "Concurrent Clients", "TP99 Latency(ms)")
    27          elif k == 2:
    28              gen_sub_graph(avs[1, 0], data_map, style, "mean_latency", "Concurrent Clients", "Mean Latency(ms)")
    29          elif k == 3:
    30              gen_sub_graph(avs[1, 1], data_map, style, "max_latency", "Concurrent Clients", "Max Latency(ms)")
    31      plt.show()
    32  
    33  
    34  def gen_sub_graph(avs: object, data_map: dict, pub_style: str, y_key: str, x_label: str, y_label: str) -> None:
    35      avs.set_xlabel(x_label)
    36      avs.set_ylabel(y_label)
    37      for k, v in data_map.items():
    38          avs.plot(v.get('x', pubilc_x), v.get(y_key), pub_style, color=line_color.get(k), alpha=1, label=k)
    39      avs.grid(axis='y', color='0.95')
    40      avs.legend(title='Frameworks')
    41  
    42  
    43  def get_compute_data_map() -> dict:
    44      return dict()
    45  
    46  
    47  def get_echo_data_map() -> dict:
    48      r0 = {
    49          "grpc": {
    50              "x": pubilc_x,
    51              "tps": [315497, 288126, 195076, 192012],
    52              "p99_latency": [6379, 1122, 1567, 1268],
    53              "mean_latency": [133, 164, 244, 247],
    54              "max_latency": [12587, 2725, 3688, 2853],
    55          },
    56          "arpc": {
    57              "x": pubilc_x,
    58              "tps": [712859, 722334, 659413, 582648],
    59              "p99_latency": [369, 317, 502, 956],
    60              "mean_latency": [67, 67, 73, 82],
    61              "max_latency": [696, 618, 902, 1424],
    62          },
    63          "rpcx": {
    64              "x": pubilc_x,
    65              "tps": [553495, 503905, 436528, 395882],
    66              "p99_latency": [405, 627, 646, 268],
    67              "mean_latency": [87, 95, 111, 49],
    68              "max_latency": [687, 1381, 1309, 1064],
    69          },
    70          "kitex": {
    71              "x": pubilc_x,
    72              "tps": [349101, 317692, 335638, 351790],
    73              "p99_latency": [759, 1060, 1188, 881],
    74              "mean_latency": [137, 147, 133, 130],
    75              "max_latency": [1464, 1860, 1694, 1309],
    76          },
    77          "net/rpc": {
    78              "x": pubilc_x,
    79              "tps": [366985, 397266, 386443, 370274],
    80              "p99_latency": [867, 796, 924, 1004],
    81              "mean_latency": [131, 120, 123, 128],
    82              "max_latency": [2015, 1084, 1636, 2229],
    83          },
    84          "lrpc": {
    85              "x": pubilc_x,
    86              "tps": [468274, 529128, 548456, 524136],
    87              "p99_latency": [515, 456, 329, 379],
    88              "mean_latency": [99, 89, 88, 92],
    89              "max_latency": [601, 648, 561, 737],
    90          },
    91          "lrpc-async": {
    92              "x": pubilc_x,
    93              "tps": [421425, 427240, 429074, 418077],
    94              "p99_latency": [601, 571, 783, 684],
    95              "mean_latency": [114, 112, 111, 114],
    96              "max_latency": [927, 815, 1578, 1345],
    97          },
    98          "arpc-async": {
    99              "x": pubilc_x,
   100              "tps": [666755, 653295, 641807, 607939],
   101              "p99_latency": [395, 470, 485, 503],
   102              "mean_latency": [71, 72, 74, 79],
   103              "max_latency": [687, 853, 1023, 807],
   104          }
   105      }
   106      return r0
   107  
   108  
   109  if __name__ == '__main__':
   110      if len(sys.argv) == 1:
   111          sys.argv.append("echo")
   112      print_type = sys.argv[1]
   113      if print_type == "echo":
   114          print_graph(get_echo_data_map(), "RPC Mock 10us Benchmark (x=Concurrent Clients,y=$ylabel)", "x--")
   115      elif print_type == "compute":
   116          print_graph(get_compute_data_map(), "RPC Compute Benchmark (x=Concurrent Clients,y=$ylabel)", "x--")