Welcome! Log In Create A New Profile

Advanced

nginx custom module multi process help

June 15, 2016 05:10PM
Hi,

I'm new to nginx development and I have to work on a custom nginx module.

The module is designed to provide a list of variables for the user to use in the nginx.conf file. Whenever those variables are used, the module makes a udp request to a helper server to get the correct value of that variable.

Example (log_format directive)

log_format test_log '$closest_chinese_restaurant $closest_ice_cream_shop';

As it's set up now (I wrote this a few months ago using Emiller's guide to nginx module development and this module on github https://github.com/leev/ngx_http_geoip2_module/blob/master/ngx_http_geoip2_module.c),

Whenever one of those variables ($closest_ice_cream_shop) is accessed, the module makes a call to the database and gets the value based on the connections ip address and returns it for use in the conf file. The problem is that many of the variables in the module can be retrieved with a single query to the helper server. As it stands now, that log directive will make two calls to the helper server : one for $closest_chinese_restaurant and one for $closest_ice_cream_shop.

How can I make it so that I only have to do one query for multiple variables? Can I get/set environment variables for use in the conf file from inside the module code? I considered making structs to hold the data so that any request will check if the ip address is the same as previously queried - and if it is, then retrieve the cached value from the structs. I'm just worried that if the server gets busy enough, there will be multiple instances of my module in different worker processes, which will lead to multiple caching arrays/structs and trying to retrieve what might not exist for that particular instance.

Right now, I have 3 getters for all of my variables : one for ints, one for floats, one for strings. They make a query to the helper server each time a variable is accessed in the conf file. Each of those setters is similar to ngx_http_geoip2_variable() in the geoip2 module linked above (they get the data via a query and set the ngx_http_variable_value_t *v).

Please help. Thanks.
Subject Author Posted

nginx custom module multi process help

de_nginx_noob June 15, 2016 05:10PM

Re: nginx custom module multi process help

itpp2012 June 15, 2016 05:54PM

Re: nginx custom module multi process help

de_nginx_noob June 16, 2016 09:36AM

Re: nginx custom module multi process help

itpp2012 June 16, 2016 11:23AM

Re: nginx custom module multi process help

de_nginx_noob June 16, 2016 01:19PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 311
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready