如何禁用g - wan servlet内部缓存



gwan版本:3.12.26

servlet类型:C和Perl

问题:

gwan内部缓存使请求不重新读取脚本

测试:

  1. create 'log' dir:

    [bash]# mkdir -p /dev/shm/random-c
    [bash]# chmod 777 /dev/shm/random-c
    
  2. 创建/道路//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] = '';
        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 
       rnd_path = (char *)/*stdlib.h->*/malloc((38 * sizeof(char)) + 1);
       rnd_path[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/

  4. 有一个20char的随机文件
  5. 这里的'问题',运行:

    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/
    

    目录只随机列出4或5个文件,而预期是1000个文件

所以回到开始的问题,如何禁用GWAN内部缓存,我试着阅读GWAN用户指南,在处理程序中设置一些东西,但没有发现任何东西(或者我错过了该指南中的一些东西)。

感谢GWAN团队为这个伟大的产品。欢迎任何回答…由于

我认为你所说的特性是微缓存。要禁用它,URI需要在200毫秒内的每个请求上是唯一的(如在URI上添加随机数)

G-WAN FAQ状态:

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

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

相关内容

  • 没有找到相关文章

最新更新