Performance Evaluation of a Module

2012-02-08 Thread Oğuzhan TOPGÜL
Hi all,
I have developed an apache module and i want to evaluate the performance of
my module.
I want to see how my module increases the load. I want to measure the
effect of my module on processor and memory.
I decided to set an evaluation environment using snmp and cacti.
I'm sending thousands of request from a laptop to the server which my
module is installed by using apache benchmark (ab). And i'm measuring load
average, memory usage data from cacti in two different cases (my module is
active and passive)

Do you think this is a good evaluation environment or do you have any
ideas, suggestions???

sincerely

Oguzhan


Inject html into response body

2011-12-04 Thread Oğuzhan TOPGÜL
Hi,
I' ve search for all the archieve but i couln't find the answer, may be i
missed up, don't know.
I'm trying to write an apache module and i want to inject some html code
into resonses.
It might be in body, header or footer. The only thing that i want to
implemet is inserting an url or a text into all response bodies without
damaging the original page that is serving.
Is there any basic way of doing that?

thanks

Oguzhan


Re: Inject html into response body

2011-12-04 Thread Oğuzhan TOPGÜL
No, there is no particular web site whoose HTML is tailored for this
purpose. At first i think this is not that much hard to add just a url or
just a text at the end of the page as a footer. But now, i think this is
not that much easy to apply.
regards
Oguzhan
On Mon, Dec 5, 2011 at 12:44 AM, Joshua Marantz jmara...@google.com wrote:

 What's your thinking on how you are going to parse the HTML to inject the
 code?  Do you need to parse arbitrary HTML from any website or is this
 filter targeted at a particular site whose HTML is tailored for this
 purpose?

 -Josh

 On Sun, Dec 4, 2011 at 5:15 PM, r...@tuxteam.de wrote:

  On Sun, Dec 04, 2011 at 11:47:37PM +0200, O??uzhan TOPG?L wrote:
   Hi,
   I' ve search for all the archieve but i couln't find the answer, may
 be i
   missed up, don't know.
   I'm trying to write an apache module and i want to inject some html
 code
   into resonses.
   It might be in body, header or footer. The only thing that i want to
   implemet is inserting an url or a text into all response bodies without
   damaging the original page that is serving.
   Is there any basic way of doing that?
 
  Well, why don't you just write an output filter that does this? I think
  Nick's book will provide all the information you need.
  Or have a look at mod_include in apache's source code.
 
   Cheers, Ralf Mattes
   thanks
  
   Oguzhan
 



Re: Binary Tree Shared Memory Problem

2011-11-28 Thread Oğuzhan TOPGÜL
Hi, is there any example mod_slotmem codes that we can understand the
usage? Or could you give me an usage example? For example we are using
apr_shm_create() in post_config, but mod_slotmem is a little bit hard to
understand i think.
And i want to ask a question,
is it a problem to create

typedef struct node {
ELEMENT node_element;
struct node *left;
struct node *right;
}NODE;

kind of struct. A struct that has two struct elements. As i mentioned
before what i'm trying to implement is a binary tree as a data structure.

regards

Oğuzhan TOPGÜL


On Mon, Nov 28, 2011 at 11:52 PM, Ignaz Birnstingl ign...@gmail.com wrote:

 Hi,

 apr_shm_baseaddr_get returns the base address for the shared memory
 segment. You will have to implement your own allocator within the shared
 memory. Also keep in mind that you can't reliably use pointers inside the
 shared memory segment, because - as the documentation states - the address
 returned by apr_shm_baseaddr_get is only usable within the callers address
 space, since this API does not guarantee that other attaching processes
 will maintain the same address mapping.
 Inter- and intra-process synchronization will be problems you will
 encounter later on.
 Btw Apache 2.3 offers mod_slotmem which helps in using shared memory -
 maybe you should have a look at it?

 -- Ignaz



Binary Tree Shared Memory Problem

2011-11-27 Thread Oğuzhan TOPGÜL
Hi,
i'm trying to use a binary that has a main node, and every leaf is also a
node that has leaves.
So i'm using a struct that's called node and this node has two nodes in it.
i defined a struct like

typedef struct element{
int IP;
int counter;
}ELEMENT;

typedef struct node {
ELEMENT node_element;
struct node *left;
struct node *right;
}NODE;

(i attached my code to the mail)

i want to add a new node into tree and i use shared memory to hold the
entire tree. If the IP of new node is smaller, i put it to he left leaf. If
IP of new node is greater, i put it into the right leaf. The right and left
leaves are also nodes and they have right and left leaves.

Anyway, my point is when i want to insert new nodes, i'm using the
apr_shm_baseaddr_get function to get the address and try to insert ner node
into it. But when i add another node as a leaf, it also changes the root
node.

the examle output of the attached code is like this (i'm printing the root
node and the right leaf node)
193168221
193168221
they are same.
what i'm expecting is
192168221
193168221

Do you have any advices?

Oğuzhan TOPGÜL
#includetime.h
#include stdio.h
#include stdlib.h
#include httpd.h
#include http_protocol.h
#include http_config.h
#include apr_shm.h
#include apr_global_mutex.h
#include util_mutex.h
#include http_log.h  //APLOG_MARK, APLOG_ERR
#include apr.h
#include apr_strings.h
#include http_core.h
#include ap_config.h

//NODE and ELEMENT struct definitions
typedef struct element{
int IP;
int counter;
}ELEMENT;

typedef struct node {
ELEMENT node_element; 
struct node *left; 
struct node *right; 
}NODE;

//Shared memory and global variable definitions
apr_shm_t *my_shm;  /* Pointer to shared memory block */ /* Shared memory structure */

struct node *newNode(int IP, struct node *node, apr_shm_t *shm) {
  node=(NODE*)apr_shm_baseaddr_get(shm);
  node-node_element.IP=IP;
  node-node_element.counter=1;
  node-left = NULL; 
  node-right = NULL;
  return(node); 
} 

struct node *insert(struct node *tree, int IP, apr_shm_t *shm) {
  // 1. If the tree is empty, return a new, single node 
  if (tree == NULL){
  return(newNode(IP, tree, shm));
  }
  
  else 
  { 
// 2. Otherwise, recur down the tree 
if (IP  tree-node_element.IP) 
tree-left = insert(tree-left, IP, shm); 
else 

if (IP  tree-node_element.IP) 
 tree-right = insert(tree-right, IP, shm);
else
{ 
if (tree-node_element.IP==IP)
   return NULL;
 } 
return(tree); // return the (unchanged) node pointer 
  } 
}

///Binary Tree ve Fonksiyonlar Bitti///

static int my_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){
apr_status_t rs;

//Shared Memory segment
rs = apr_shm_create(my_shm, sizeof(NODE), NULL, pconf);
   

apr_pool_cleanup_register(pconf, NULL, shm_cleanup_wrapper, apr_pool_cleanup_null);
return OK;
}

static int my_handler(request_rec *r)
{
   apr_status_t rs;
   
   if (strcmp(r-handler, myhandler)) {
return DECLINED;
}

   
   binarytree=(NODE*)apr_shm_baseaddr_get(my_shm);
   binarytree=insert(binarytree,19216822,my_shm);
   binarytree=insert(binarytree,19316822,my_shm);

   ap_rprintf(r, %i%i\n, binarytree-node_element.IP, binarytree-node_element.counter);
   ap_rprintf(r, %i%i\n, binarytree-right-node_element.IP, binarytree-right-node_element.counter);
   
return OK;
}

static void my_hooks(apr_pool_t *pool)
{
ap_hook_pre_config(my_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(my_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(my_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(my_handler, NULL, NULL, APR_HOOK_MIDDLE);
}

module AP_MODULE_DECLARE_DATA my_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
my_hooks
};


Re: basic example shared memory code

2011-11-23 Thread Oğuzhan TOPGÜL
When i delete exit(1), nothing has changed but when i commented out all the
mutexes it works, counter is working well. That's great. :)
that means shared memory is working well.

in terms of mutexes
i need to create mutex in post config
in handler
1. lock mutex
2. process global variable
3. unlcok mutex

If i'm right what is the problem with that code, do you have any ideas or
advices about these segmentation faults.

Oğuzhan TOPGÜL


On Wed, Nov 23, 2011 at 12:39 AM, Sorin Manolache sor...@gmail.com wrote:

 On Tue, Nov 22, 2011 at 21:25, Oğuzhan TOPGÜL oguzhantop...@gmail.com
 wrote:
  hey guys,
  i'm in terrible with these shared memory.
  I tried to write a basic module by looking at the examples that basic
 module
  just holds a counter and prints it to the client.
  when i compile the code attached, i got no error messages. But in apache
  error.log file i got
  lots of
  [notice] child pid 32653 exit signal Segmentation fault (11)
  and my module does not working.
  if you have time to look at my code and send me your advices i'll be
  appreciated. Because i'm getting crazy about these shared memory
 concepts.
  I just want to define a global variable and process it in each request
 from
  different sources.
  Regards,
  Oğuzhan TOPGÜL

 First remove the exit(1) from child_init. Otherwise apache does not
 succeed in creating any children.

 If this does not solve your problem, comment all lines dealing with
 the mutex and retry. I'm not saying that you don't need mutexes but
 commenting them out would at least restrict the area where the
 segfaults happen.

 S

 
 
  On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL oguzhantop...@gmail.com
 
  wrote:
 
  Thank you guys so much.
  What i want to do with shared memory is to hold the requester IPs and a
  counter that holds how many times an IP made request. I'm planning to
 hold
  them in a binary tree.
  I thought holding these IPs and counters in a file is slower than
 holding
  them in a shared memory because of the file I/O loss. And using binary
 tree
  as a data structure is going to make my search process faster and
 easier.
  Do you have any suggestions about shared memory-file usage or data
  structure usage.
  Regards
  Oğuzhan TOPGÜL
 
 
  On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew n...@apache.org wrote:
 
  On Tue, 22 Nov 2011 09:41:02 -0500
  Pranesh Vadhirajan vadhira...@teralogics.com wrote:
 
   Nick, can you suggest some of these higher-level abstractions,
 please?
I have been trying to make a module of mine work with a POSIX
 shared memory
   implementation, but I'm going nowhere with that.  Are you referring
 to the
   apache shared memory implementation (apr_shm_...) or something else?
  Either
   way, if you could suggest what I should look into, it would be
 greatly
   appreciated.
 
  apr_shm is the old way of doing it.
 
  Today I'd recommend looking at mod_slotmem, and the socache modules.
  I used the latter for mod_authn_socache, which is a simple example.
 
  --
  Nick Kew
 
 
 



basic example shared memory code

2011-11-22 Thread Oğuzhan TOPGÜL
Hi guys, I'm trying to learn shared memory and mutex concepts and i need an
example shared memory apache module code that was written in c.
I found some codes, but none of them is working properly. I'm using ubuntu
10.10 as a development environment. Do you have any basic codes like shared
memory counter or etc.
If you can send me a working example, i'll be appreciated because i'm very
very confused and stuck about shared memory concepts. I just need a basic
example code snippet

thanks

Oğuzhan TOPGÜL


Re: basic example shared memory code

2011-11-22 Thread Oğuzhan TOPGÜL
hey guys,
i'm in terrible with these shared memory.
I tried to write a basic module by looking at the examples that basic
module just holds a counter and prints it to the client.
when i compile the code attached, i got no error messages. But in apache
error.log file i got
lots of
[notice] child pid 32653 exit signal Segmentation fault (11)
and my module does not working.
if you have time to look at my code and send me your advices i'll be
appreciated. Because i'm getting crazy about these shared memory concepts.
I just want to define a global variable and process it in each request from
different sources.

Regards,
Oğuzhan TOPGÜL


On Tue, Nov 22, 2011 at 9:14 PM, Oğuzhan TOPGÜL oguzhantop...@gmail.comwrote:

 Thank you guys so much.
 What i want to do with shared memory is to hold the requester IPs and a
 counter that holds how many times an IP made request. I'm planning to hold
 them in a binary tree.
 I thought holding these IPs and counters in a file is slower than holding
 them in a shared memory because of the file I/O loss. And using binary tree
 as a data structure is going to make my search process faster and easier.
 Do you have any suggestions about shared memory-file usage or data
 structure usage.

 Regards
 Oğuzhan TOPGÜL



 On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew n...@apache.org wrote:

 On Tue, 22 Nov 2011 09:41:02 -0500
 Pranesh Vadhirajan vadhira...@teralogics.com wrote:

  Nick, can you suggest some of these higher-level abstractions, please?
  I have been trying to make a module of mine work with a POSIX shared
 memory implementation, but I'm going nowhere with that.  Are you referring
 to the apache shared memory implementation (apr_shm_...) or something else?
  Either way, if you could suggest what I should look into, it would be
 greatly appreciated.

 apr_shm is the old way of doing it.

 Today I'd recommend looking at mod_slotmem, and the socache modules.
 I used the latter for mod_authn_socache, which is a simple example.

 --
 Nick Kew



#include stdio.h
#include stdlib.h
#include httpd.h
#include http_protocol.h
#include http_config.h
#include apr_shm.h
#include apr_global_mutex.h
#include util_mutex.h
#include http_log.h  //APLOG_MARK, APLOG_ERR 

#include apr.h
#include apr_strings.h
#include http_core.h
#include ap_config.h

apr_shm_t *mod_basic_shm;/* Pointer to shared memory block */ /* Shared memory structure */
apr_global_mutex_t *mod_basic_mutex; /* Lock around shared memory segment access */
static const char *mod_basic_mutex_type=mod-basic-mutex-shm;


typedef struct mod_basic_data{
int count;
}counter_data;


static apr_status_t shm_cleanup_wrapper(void *unused){
if(mod_basic_shm)
return apr_shm_destroy(mod_basic_shm);
return OK;
}


static int mod_basic_pre_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp){
ap_mutex_register(pconf, mod_basic_mutex_type, NULL, APR_LOCK_DEFAULT, 0);
return OK;
}


static int mod_basic_post_config(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s){
apr_status_t rs;
counter_data *counter;
  
//Create shared memory segment
rs = apr_shm_create(mod_basic_shm, sizeof(counter_data), NULL, pconf);
  
//counter equals to zero
counter=(counter_data*)apr_shm_baseaddr_get(mod_basic_shm);
counter-count=0;

//Create mutex
rs=ap_global_mutex_create(mod_basic_mutex, NULL, mod_basic_mutex_type, NULL, s, pconf, 0);

//Destroy the shm segment when the configuration pool gets destroyed
apr_pool_cleanup_register(pconf, NULL, shm_cleanup_wrapper, apr_pool_cleanup_null);
return OK;
}

static void mod_basic_child_init(apr_pool_t *p, server_rec *s){
apr_status_t rs;

//open mutex to init child
rs=apr_global_mutex_child_init(mod_basic_mutex, NULL, p);
exit(1);

}

static int basic_handler(request_rec *r)
{
   apr_status_t rs;
   counter_data *counter;
   
   if (strcmp(r-handler, basic)) {
return DECLINED;
}
   
   //lock the global variable before proceed it
   rs=apr_global_mutex_lock(mod_basic_mutex); 
  
   //lets increase the counter
   counter = (counter_data*)apr_shm_baseaddr_get(mod_basic_shm);
   counter-count++;
   ap_rprintf(r,%i,counter-count);
   
   // Unlock mutex after increase the counter
   rs=apr_global_mutex_unlock(mod_basic_mutex);

return OK;
}


static void basic_hooks(apr_pool_t *pool)
{
ap_hook_pre_config(mod_basic_pre_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(mod_basic_post_config, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_child_init(mod_basic_child_init, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_handler(basic_handler, NULL, NULL, APR_HOOK_MIDDLE);
}


module AP_MODULE_DECLARE_DATA basic_module = {
STANDARD20_MODULE_STUFF,
NULL,
NULL,
NULL,
NULL,
NULL,
basic_hooks
};



Re: basic example shared memory code

2011-11-22 Thread Oğuzhan TOPGÜL
Thank you guys so much.
What i want to do with shared memory is to hold the requester IPs and a
counter that holds how many times an IP made request. I'm planning to hold
them in a binary tree.
I thought holding these IPs and counters in a file is slower than holding
them in a shared memory because of the file I/O loss. And using binary tree
as a data structure is going to make my search process faster and easier.
Do you have any suggestions about shared memory-file usage or data
structure usage.

Regards
Oğuzhan TOPGÜL


On Tue, Nov 22, 2011 at 5:15 PM, Nick Kew n...@apache.org wrote:

 On Tue, 22 Nov 2011 09:41:02 -0500
 Pranesh Vadhirajan vadhira...@teralogics.com wrote:

  Nick, can you suggest some of these higher-level abstractions, please?
  I have been trying to make a module of mine work with a POSIX shared
 memory implementation, but I'm going nowhere with that.  Are you referring
 to the apache shared memory implementation (apr_shm_...) or something else?
  Either way, if you could suggest what I should look into, it would be
 greatly appreciated.

 apr_shm is the old way of doing it.

 Today I'd recommend looking at mod_slotmem, and the socache modules.
 I used the latter for mod_authn_socache, which is a simple example.

 --
 Nick Kew