Horus-K opened a new issue #73:
URL: https://github.com/apache/apisix-go-plugin-runner/issues/73


   ### Issue description
   I use the official demo to directly return the html file, but its 
performance is not good
   ### Environment
   
   * APISIX Go Plugin Runner's version: 0.2.0
   * APISIX version: apisix:2.11.0
   * Go version:1.。17
   * OS (cmd: `uname -a`): centos7.8
   I have 3 apisix instances  2c2g
   
![image](https://user-images.githubusercontent.com/48319268/159211468-f5baf8fc-2b47-4e95-8124-ea7d668cfccf.png)
   some request rt is very high
   
![image](https://user-images.githubusercontent.com/48319268/159211521-65dd4f8e-88bc-4770-9206-e4d4de3ca3d1.png)
   code
   ```
   /*
    * Licensed to the Apache Software Foundation (ASF) under one or more
    * contributor license agreements.  See the NOTICE file distributed with
    * this work for additional information regarding copyright ownership.
    * The ASF licenses this file to You under the Apache License, Version 2.0
    * (the "License"); you may not use this file except in compliance with
    * the License.  You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    * See the License for the specific language governing permissions and
    * limitations under the License.
    */
   
   package plugins
   
   import (
        "encoding/base64"
        "encoding/json"
        pkgHTTP "github.com/apache/apisix-go-plugin-runner/pkg/http"
        "github.com/apache/apisix-go-plugin-runner/pkg/log"
        "github.com/apache/apisix-go-plugin-runner/pkg/plugin"
        "net/http"
   )
   
   func init() {
        log.Infof("init开始...")
        err := plugin.RegisterPlugin(&Say{})
        if err != nil {
                log.Fatalf("注册插件失败 say: %s", err)
        }
   }
   
   // Say is a demo to show how to return data directly instead of proxying
   // it to the upstream.
   type Say struct {
   }
   
   type SayConf struct {
        Body   string `json:"body"`
   }
   
   func (p *Say) Name() string {
        return "say"
   }
   
   func (p *Say) ParseConf(in []byte) (interface{}, error) {
        log.Infof("解析配置开始...")
        conf := SayConf{}
        err := json.Unmarshal(in, &conf)
        return conf, err
   }
   
   func (p *Say) Filter(conf interface{}, w http.ResponseWriter, r 
pkgHTTP.Request) {
        //获取配置文件对应值
        body := conf.(SayConf).Body
   
   
        if len(body) == 0 {
                log.Errorf("Body为空")
                return
        }
        resBody, err := base64.StdEncoding.DecodeString(body)
        if err != nil {
                log.Errorf("Base64解码不正确")
                return
        }
        w.Header().Set("Content-Type", "text/html")
        _, err = w.Write([]byte(resBody))
        if err != nil {
                log.Errorf("failed to write: %s", err)
        }
   }
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to