All Products
Search
Document Center

API Gateway:Plug-in performance references

Last Updated:Jan 07, 2025

This topic describes the performance of the built-in plug-ins of Cloud-native API Gateway and the custom plug-ins that are developed based on different programming languages. The performance is assessed based on the request latency.

Performance of built-in plug-ins

The built-in plug-ins of Cloud-native API Gateway provide a latency of microseconds. For example, the key-auth plug-in processes each request with a latency of about 20 microseconds. The basic-auth plug-in processes each request with a latency of about 30 microseconds.

Performance of custom plug-ins

The following examples compare the performance of multiple plug-ins that are developed based on different programming languages. All the plug-ins are used to implement the following processing logic: Request headers are configured for 20 consecutive times, obtained for 20 consecutive times, and then removed for 20 consecutive times.

  • Sample code for a custom plug-in that is developed based on C++

    FilterHeadersStatus PluginContext::onRequestHeaders(uint32_t, bool) {
      std::string fake_header_key_prefix = "fake_key_";
      std::string fake_header_value_prefix = "fake_value_";
      // Add 20 headers to request headers
      for (size_t i = 0; i < 20; i++) {
        addRequestHeader(fake_header_key_prefix + std::to_string(i),
                         fake_header_value_prefix + std::to_string(i));
      }
    
      // Check 20 times headers.
      for (size_t i = 0; i < 20; i++) {
        getRequestHeader(fake_header_key_prefix + std::to_string(i));
      }
    
      // remove add headers
      for (size_t i = 0; i < 20; i++) {
        removeRequestHeader(fake_header_key_prefix + std::to_string(i));
      }
      return FilterHeadersStatus::Continue;
    }
  • Sample code for a custom plug-in that is developed based on Golang

    func (ctx *httpContext) OnHttpRequestHeaders(numHeaders int, endOfStream bool) types.Action {
            fake_header_key_prefix := "fake_key_"
            fake_header_value_prefix := "fake_value_"
            for i := 0; i < 20; i++ {
                    proxywasm.AddHttpRequestHeader(fake_header_key_prefix+strconv.Itoa(i),
                            fake_header_value_prefix+strconv.Itoa(i))
            }
            for i := 0; i < 20; i++ {
                    proxywasm.GetHttpRequestHeader(fake_header_key_prefix + strconv.Itoa(i))
            }
            for i := 0; i < 20; i++ {
                    proxywasm.RemoveHttpRequestHeader(fake_header_key_prefix + strconv.Itoa(i))
            }
            return types.ActionContinue
    }
  • Sample code for a custom plug-in that is developed based on Rust

    fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action {
        for i in 0..20 {
            let key = "fake_key_".to_string() + &i.to_string();
            let value = "fake_value_".to_string() + &i.to_string();
            self.set_http_request_header(&key, Some(&value));
        }
        for i in 0..20 {
            let key = "fake_key_".to_string() + &i.to_string();
            self.get_http_request_header(&key);
        }
        for i in 0..20 {
            let key = "fake_key_".to_string() + &i.to_string();
            self.set_http_request_header(&key, None);
        }
        Action::Continue
    }
  • Sample code for a custom plug-in that is developed based on AssemblyScript

    function onRequestHeaders(a: u32, end_of_stream: bool): FilterHeadersStatusValues {
      let fake_header_key_prefix: string = "fake_key_";
      let fake_header_value_prefix: string = "fake_value_";
      for (let i = 0; i < 20; i++) {
         stream_context.headers.request.add(fake_header_key_prefix + i.toString(), fake_header_value_prefix + i.toString())
      }
      for (let i = 0; i < 20; i++) {
         stream_context.headers.request.get(fake_header_key_prefix + i.toString())
      }
      for (let i = 0; i < 20; i++) {
         stream_context.headers.request.remove(fake_header_key_prefix + i.toString())
      }
      return FilterHeadersStatusValues.Continue;
    }

Performance comparison among custom plug-ins developed based on different languages

Programming language

Increased request latency

C++

0.19 ms

Golang

0.20 ms

Rust

0.21 ms

AssemblyScript

0.21 ms

The comparison result shows that the custom plug-ins developed based on different programming languages provide similar performance in terms of the request latency.