1

gwan version: 3.12.26

servlet type: C and Perl

problem:

gwan internal cache make request not re-read the script

test:

  1. create 'log' dir :

    [bash]# mkdir -p /dev/shm/random-c
    [bash]# chmod 777 /dev/shm/random-c
    
  2. create /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. run on browser:

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

    then you should have one 20char random file at /dev/shm/random-c/

  4. here the 'problem', run:

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

    my ubuntu have output:

    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
    

    try:

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

    the directory only list 4 or 5 random files, which expected was 1000files

  5. tested on random.c and perl's version random.pl

so the back to beginning question, how to disable GWAN internal cache, I try to read gwan user guide for set something in handler, but found nothing (or I miss something in that guide ).

thanks for GWAN team for this great product. any answer welcome .. thanks

4

1 回答 1

0

我认为您正在谈论的功能是微缓存。要禁用它,URI 需要在 200 毫秒内对每个请求都是唯一的。(就像在 URI 上添加随机数)

G-WAN 常见问题解答状态:

“为了免除对前端缓存服务器的需求(并让 G-WAN 用作缓存反向代理),G-WAN 支持微缓存,这是一种 RESTful 功能。当以高并发调用给定 URI 时以及生成payload 需要很长时间,然后 G-WAN 会自动缓存一个页面 200 毫秒(Internet 上的平均延迟)以确保缓存是最新的:在 200 毫秒内,连续请求提供预期的结果。为防止触发微缓存,请对并发请求使用不断变化的查询参数(每个用户会话 id、随机数、计数器等)。

请注意,对于 v4.10+,默认情况下禁用缓存,请查看gwan/init.c文件。

于 2012-12-27T17:34:57.663 回答