Built-in plug-ins of Cloud-native API Gateway add only microseconds of latency per request. Custom plug-ins developed in C++, Golang, Rust, and AssemblyScript deliver similar performance.
Performance of built-in plug-ins
Built-in plug-ins add microsecond-level latency to each request. For example, the key-auth plug-in adds about 20 microseconds and the basic-auth plug-in adds about 30 microseconds.
Performance of custom plug-ins
The following examples implement the same processing logic in different programming languages: add 20 request headers, read them 20 times, and then remove them.
-
C++ sample code
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; } -
Golang sample code
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 } -
Rust sample code
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 } -
AssemblyScript sample code
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 |
Custom plug-ins developed in different languages deliver similar request latency.