1

gwanバージョン:3.12.26

サーブレットタイプ:CおよびPerl

問題:

gwan internal cache make request not reread the script

テスト:

  1. 'log' dirを作成します:

    [bash]# mkdir -p /dev/shm/random-c
    [bash]# chmod 777 /dev/shm/random-c
    
  2. /path/to/gwan/0.0.0.0_8080/#0.0.0.0/csp/random.cを作成します

    // ============================================================================
    // C servlet sample for the G-WAN Web Application Server (http://trustleap.ch/)
    // ----------------------------------------------------------------------------
    // hello.c: just used with Lighty's Weighttp to benchmark a minimalist servlet
    // ============================================================================
    // imported functions:
    //   get_reply(): get a pointer on the 'reply' dynamic buffer from the server
    //    xbuf_cat(): like strcat(), but it works in the specified dynamic buffer
    // ----------------------------------------------------------------------------
    #include <sys/time.h>
    #include "gwan.h" // G-WAN exported functions
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    //------------------
    void init_random(){
        struct /*sys/time.h->*/timeval res;
        /*sys/time.h->*/gettimeofday(&res,NULL);
       /*stdlib.h->*/srand( (unsigned int)/*stdlib.h->*/time(NULL) + res.tv_usec);
    }
    
    //------------------
    char *get_rnd_char(int num){
        char *char_list = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        int  char_list_len = 62;
        char *ret = (char *)/*stdlib.h->*/malloc((num * sizeof(char)) + 1);
        int i,r;
    
    
        for(i=0;i<num;i++){
            r=(int) (/*stdlib.h->*/rand() % char_list_len);
            ret[i] = char_list[r==char_list_len ? r-1 : r];
        }
        ret[num] = '\0';
        return ret;
    }
    
    //------------------
    int main(int argc, char *argv[])
    {
        char *rnd_out; //-- random data for browser output and file input
        char *rnd_file; //-- random file
        char *rnd_path; //-- for speed let's make on ramdisk /dev/shm/random-c/
        char *t;
        FILE *F;
    
        int num_char=10;
        int arg_cnt=1;
    
        if(argc>0){
            //-- why nobody love C ? one of the reason is these kind parsing thing
            while ((t = /*string.h->*/strtok(argv[0], "=")) != NULL) {
                argv[0] = NULL;
                if(arg_cnt == 2){
                    num_char = /*stdlib.h->*/atoi(t);
                }
                arg_cnt++;
            }
        }else{
            //-- get random number betwen 1 to 1000
            num_char = (rand() % 1000)+1;
        }
    
        init_random();
    
    
       //-- create random data
        rnd_out = get_rnd_char(num_char);
    
    
        //-- creating "log" path
        //-- why nobody love C ? more reason
       rnd_file = get_rnd_char(20);
       // "/dev/shm/random-c/xxxxxxxxxxxxxxxxxxxx" -> 38 chars + 1 for \0
       rnd_path = (char *)/*stdlib.h->*/malloc((38 * sizeof(char)) + 1);
       rnd_path[0] = '\0';
       /*string.h->*/strcat(rnd_path,"/dev/shm/random-c/");
       /*string.h->*/strcat(rnd_path,rnd_file);
    
        //-- save to file
        F = /*stdio.h->*/fopen(rnd_path,"w");
            /*stdio.h->*/fprintf(F,"%s",rnd_out);
        /*stdio.h->*/fclose(F);
    
    
       //-- send output to browser
       /*gwan.h->*/xbuf_cat(get_reply(argv), rnd_out);
    
    
        //-- cleanup memory
        //-- why nobody love C ? MAIN reason: no easy way of memory management
       /*stdlib.h->*/free(rnd_file);
       /*stdlib.h->*/free(rnd_out);
       /*stdlib.h->*/free(rnd_path);
    
       return 200; // return an HTTP code (200:'OK')
    }
    
    // ============================================================================
    // End of Source Code
    // ============================================================================
    
  3. ブラウザで実行:

    http://localhost:8080/?random.c 
    

    次に、/ dev / shm /random-c/に1つの20charランダムファイルが必要です。

  4. ここで「問題」を実行します。

    ab -n 1000 'http://localhost:8080/?random.c'
    

    私のubuntuには次の出力があります:

    Finished 1000 requests
    
    
    Server Software:        G-WAN
    Server Hostname:        localhost
    Server Port:            8080
    
    Document Path:          /?random.c
    Document Length:        440 bytes
    
    Concurrency Level:      1
    Time taken for tests:   0.368 seconds
    Complete requests:      1000
    Failed requests:        361
       (Connect: 0, Receive: 0, Length: 361, Exceptions: 0)
    Write errors:           0
    Total transferred:      556492 bytes
    HTML transferred:       286575 bytes
    Requests per second:    2718.73 [#/sec] (mean)
    Time per request:       0.368 [ms] (mean)
    Time per request:       0.368 [ms] (mean, across all concurrent requests)
    Transfer rate:          1477.49 [Kbytes/sec] received
    

    試す:

    [bash]# ls /dev/shm/random-c/
    

    ディレクトリには、1000ファイルであると予想される4つまたは5つのランダムファイルのみがリストされます。

  5. random.cおよびperlのバージョンrandom.plでテスト済み

したがって、最初の質問に戻って、GWAN内部キャッシュを無効にする方法を説明します。gwanユーザーガイドを読んでハンドラーに何かを設定しようとしましたが、何も見つかりませんでした(またはそのガイドに何かがありません)。

この素晴らしい製品を提供してくれたGWANチームに感謝します。どんな答えでも歓迎..ありがとう

4

1 に答える 1

0

あなたが話している機能はマイクロキャッシングだと思います。これを無効にするには、200ミリ秒以内に各リクエストでURIが一意である必要があります。(URIに乱数を追加するように)

G-WAN FAQの状態:

「フロントエンドキャッシュサーバーの必要性をなくすために(そしてG-WANをキャッシングリバースプロキシとして使用できるようにするために)G-WANはマイクロキャッシング、RESTful機能をサポートします。特定のURIが高い同時性で呼び出され、生成する場合ペイロードに時間がかかる場合、G-WANは自動的にページを200ミリ秒(インターネット上の平均レイテンシ)キャッシュして、キャッシュが最新であることを確認します。200ミリ秒以内に、連続したリクエストが期待どおりのリクエストを提供します。結果。マイクロキャッシュがトリガーされないようにするには、同時リクエストに対して変更するクエリパラメーター(ユーザーセッションIDごと、ランダム、カウンターなど)を使用します。」

v4.10 +の場合、キャッシュはデフォルトで無効になっていることに注意してくださいgwan/init.c。ファイルを確認してください。

于 2012-12-27T17:34:57.663 に答える