[OpenSIPS-Users] global variables
Another day, another question: I like to declare some variables at the beginning of my script and use this at several places, the variables must be known till restart. something like ie: $my_eth0_interface = "89.1.2.3"; $my_eth1_interface = "10.0.1.2"; $my_default_timeout = 100; etc etc. I was looking at cache_store() but don't know what to use best in this case. Any advise how to accomplish this? Gr. Jan -- View this message in context: http://opensips-open-sip-server.1449251.n2.nabble.com/global-variables-tp7389514p7389514.html Sent from the OpenSIPS - Users mailing list archive at Nabble.com. ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
[OpenSIPS-Users] Global Variables
Hey all,I'm wondering if there is a way to use global variables? I see that $var variables are persistent across the process, but I need something that will persist across all processes. Right now, I'm using memcache, but I'm not sure if I'll have race conditions relying on that as I expect many processes to be accessing and updating the globals for every call. Thanks, Brett ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
[OpenSIPS-Users] global variables
Hi, one probably stupid question, I'm customizing siptrace module further, so I am adding queue for db writing, in case we loose db connectivity and threads for popping the queue and writing to db. Written almost everything, but just to be sure, if I use global variable for linked list, will they keep the values until opensips ends, or will they always be reinitialized, because for test purposes I defined counter but it's always initialized to default value. Best regards, Josip ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
Hello, If you want to accomplish this, you can use the localcache module. In startup_route, initialize all of your needed 'constants' and store them with no expiry time ( cache_store ), and when you want to use them later on, just make a call to cache_fetch. Regards Vlad Paiu OpenSIPS Developer http://www.opensips-solutions.com On 03/20/2012 05:38 PM, Jan D. wrote: Another day, another question: I like to declare some variables at the beginning of my script and use this at several places, the variables must be known till restart. something like ie: $my_eth0_interface = "89.1.2.3"; $my_eth1_interface = "10.0.1.2"; $my_default_timeout = 100; etc etc. I was looking at cache_store() but don't know what to use best in this case. Any advise how to accomplish this? Gr. Jan -- View this message in context: http://opensips-open-sip-server.1449251.n2.nabble.com/global-variables-tp7389514p7389514.html Sent from the OpenSIPS - Users mailing list archive at Nabble.com. ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
Use m4 macro processor. http://www.opensips.org/Resources/DocsTools -- Nick 2012/3/20 Jan D. > Another day, another question: > > I like to declare some variables at the beginning of my script and use this > at several places, the variables must be known till restart. > > something like ie: > > $my_eth0_interface = "89.1.2.3"; > $my_eth1_interface = "10.0.1.2"; > $my_default_timeout = 100; > etc etc. > > I was looking at cache_store() but don't know what to use best in this > case. > > Any advise how to accomplish this? > > Gr. > > Jan > > -- > View this message in context: > http://opensips-open-sip-server.1449251.n2.nabble.com/global-variables-tp7389514p7389514.html > Sent from the OpenSIPS - Users mailing list archive at Nabble.com. > > ___ > Users mailing list > Users@lists.opensips.org > http://lists.opensips.org/cgi-bin/mailman/listinfo/users > ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] Global Variables
Brett, The $var variables are persistent per transaction. For the entire dialog, use dialog variables: http://www.opensips.org/html/docs/modules/1.5.x/dialog.html The key functions here are store_dlg_value() and fetch_dlg_value(), or set_dlg_flag() and is_dlg_flag_set(). Now if you're looking to share values between different dialogs, you could have a look at set_dlg_profile() and get_profile_size(), but I'm not sure that's what you're looking for. There is some great sample code here: http://www.opensips.org/Resources/DocsTutConcurrentCalls I had the need to store values across multiple profiles and across multiple servers in real-time; my solution was to use avp_db_query() and build my own database-backended storage system that all Opensips processes, regardless of which server they were on, could access. Needless to say this is not a lightweight solution and I'm certain it will require a beefy database server as we get larger, but it was the only way I could see to make it happen... Jeff From: users-boun...@lists.opensips.org [mailto:users-boun...@lists.opensips.org] On Behalf Of Brett Nemeroff Sent: Sunday, October 04, 2009 10:27 AM To: users@lists.opensips.org Subject: [OpenSIPS-Users] Global Variables Hey all, I'm wondering if there is a way to use global variables? I see that $var variables are persistent across the process, but I need something that will persist across all processes. Right now, I'm using memcache, but I'm not sure if I'll have race conditions relying on that as I expect many processes to be accessing and updating the globals for every call. Thanks, Brett ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] Global Variables
2009/10/4 Brett Nemeroff : > I'm wondering if there is a way to use global variables? $shv(...) does that: http://www.opensips.org/html/docs/modules/1.5.x/cfgutils.html#id271355 > but I'm not sure if I'll have race conditions relying on that as I expect > many processes > to be accessing and updating the globals for every call. If you're doing something especially tricky, you might consider writing a module to do that... What is it exactly that you want to achieve? -- KTHXBYE, Stanisław Pitucha, Gradwell Voip Engineer ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] Global Variables
Hi! Memcache with localcache (shared memory)? As far as I understand you'll not run into race condition, because there're a locks at inside localcache hashtable. Also shared memory supposed to be very fast :) -- Best Regards, Alex Massover VoIP R&D TL Jajah Inc. From: users-boun...@lists.opensips.org [mailto:users-boun...@lists.opensips.org] On Behalf Of Brett Nemeroff Sent: Sunday, October 04, 2009 6:27 PM To: users@lists.opensips.org Subject: [OpenSIPS-Users] Global Variables Hey all, I'm wondering if there is a way to use global variables? I see that $var variables are persistent across the process, but I need something that will persist across all processes. Right now, I'm using memcache, but I'm not sure if I'll have race conditions relying on that as I expect many processes to be accessing and updating the globals for every call. Thanks, Brett This mail was received via Mail-SeCure System. This mail was sent via Mail-SeCure System. ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] Global Variables
Hey Alex,I've just tried it with memcache and that works great.. Very fast.. just a little clumsy looking in the scripts; but otherwise works great. Thanks, Brett On Mon, Oct 5, 2009 at 4:36 AM, Alex Massover wrote: > Hi! > > > > Memcache with localcache (shared memory)? > > As far as I understand you’ll not run into race condition, because there’re > a locks at inside localcache hashtable. Also shared memory supposed to be > very fast J > > > > -- > > Best Regards, > > Alex Massover > > VoIP R&D TL > > Jajah Inc. > > *From:* users-boun...@lists.opensips.org [mailto: > users-boun...@lists.opensips.org] *On Behalf Of *Brett Nemeroff > *Sent:* Sunday, October 04, 2009 6:27 PM > > *To:* users@lists.opensips.org > *Subject:* [OpenSIPS-Users] Global Variables > > > > Hey all, > > I'm wondering if there is a way to use global variables? I see that $var > variables are persistent across the process, but I need something that will > persist across all processes. Right now, I'm using memcache, but I'm not > sure if I'll have race conditions relying on that as I expect many processes > to be accessing and updating the globals for every call. > > > > Thanks, > > Brett > > > > > This mail was received via Mail-SeCure System. > > > This mail was sent via Mail-SeCure System. > > ___ > Users mailing list > Users@lists.opensips.org > http://lists.opensips.org/cgi-bin/mailman/listinfo/users > > ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] Global Variables
Memcache can work with 3 types of storage: http://www.opensips.org/Resources/DocsTutMemcache "A memory caching system can be via the local shared memory (see Local Cache module) or via the System V shared memory (mem cache shared across independent applications) or via the MemCache server." You probably need localcache for the best perforamce. -- Best Regards, Alex Massover VoIP R&D TL Jajah Inc. From: users-boun...@lists.opensips.org [mailto:users-boun...@lists.opensips.org] On Behalf Of Brett Nemeroff Sent: Monday, October 05, 2009 2:18 PM To: OpenSIPS users mailling list Subject: Re: [OpenSIPS-Users] Global Variables Hey Alex, I've just tried it with memcache and that works great.. Very fast.. just a little clumsy looking in the scripts; but otherwise works great. Thanks, Brett On Mon, Oct 5, 2009 at 4:36 AM, Alex Massover mailto:a...@jajah.com>> wrote: Hi! Memcache with localcache (shared memory)? As far as I understand you'll not run into race condition, because there're a locks at inside localcache hashtable. Also shared memory supposed to be very fast :) -- Best Regards, Alex Massover VoIP R&D TL Jajah Inc. From: users-boun...@lists.opensips.org<mailto:users-boun...@lists.opensips.org> [mailto:users-boun...@lists.opensips.org<mailto:users-boun...@lists.opensips.org>] On Behalf Of Brett Nemeroff Sent: Sunday, October 04, 2009 6:27 PM To: users@lists.opensips.org<mailto:users@lists.opensips.org> Subject: [OpenSIPS-Users] Global Variables Hey all, I'm wondering if there is a way to use global variables? I see that $var variables are persistent across the process, but I need something that will persist across all processes. Right now, I'm using memcache, but I'm not sure if I'll have race conditions relying on that as I expect many processes to be accessing and updating the globals for every call. Thanks, Brett This mail was received via Mail-SeCure System. This mail was sent via Mail-SeCure System. ___ Users mailing list Users@lists.opensips.org<mailto:Users@lists.opensips.org> http://lists.opensips.org/cgi-bin/mailman/listinfo/users This mail was received via Mail-SeCure System. This mail was sent via Mail-SeCure System. ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
Hi Josip, Josip Djuricic wrote: > Hi, > > one probably stupid question, I'm customizing siptrace module further, > so I am adding queue for db writing, in case we loose db connectivity > and threads for popping the queue and writing to db. > why don't you use the new db_virtual module with a failover configuration: define a new virtual db connection that has behind a primary mysql conn and a secondary (failover only) flatstore/dbtext conn. So, if DB fails, you will start writing to a local file. > Written almost everything, but just to be sure, if I use global variable > for linked list, will they keep the values until opensips ends, or will > they always be reinitialized, because for test purposes I defined > counter but it's always initialized to default value. > To be honest I do not advices using thread in current opensips as you have multiple processes already. And the combination of threads and processes may be unpredictable. Anyhow, regarding your question - the global vars are init only at startup time - but note that "global" is as visibility in the code and not global "in all processes". Each process will have its own copy of the var. Regards, Bogdan -- Bogdan-Andrei Iancu www.voice-system.ro ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
Sorry I missed this email, I'll think about using db_virtual, but back to global vars issue, for a test I defined just a global counter variable, and created new function inside siptrace module, so every time a siptrace function is called I also call this function and do counter ++. since counter is defined outside of the function, it should be defined as global variable, so I've outputed with LM_INFO value of counter and it's always 1, sometime it gets pass that value, but on the next call it's 1 again. Perhaps I'm thinking wrong and siptrace module is not having it's own fork, but instead loads inside other forks? That would explain this behaviour. If that is the case, what would you suggest? I would then need to use interprocess communication, perhaps I could reuse something from opensips? Best regards, Josip Bogdan-Andrei Iancu wrote: > Hi Josip, > > Josip Djuricic wrote: >> Hi, >> >> one probably stupid question, I'm customizing siptrace module further, >> so I am adding queue for db writing, in case we loose db connectivity >> and threads for popping the queue and writing to db. >> > why don't you use the new db_virtual module with a failover > configuration: define a new virtual db connection that has behind a > primary mysql conn and a secondary (failover only) flatstore/dbtext > conn. So, if DB fails, you will start writing to a local file. >> Written almost everything, but just to be sure, if I use global variable >> for linked list, will they keep the values until opensips ends, or will >> they always be reinitialized, because for test purposes I defined >> counter but it's always initialized to default value. >> > To be honest I do not advices using thread in current opensips as you > have multiple processes already. And the combination of threads and > processes may be unpredictable. > Anyhow, regarding your question - the global vars are init only at > startup time - but note that "global" is as visibility in the code and > not global "in all processes". Each process will have its own copy of > the var. > > Regards, > Bogdan > ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
Hi Josip, Josip Djuricic wrote: > Sorry I missed this email, > > I'll think about using db_virtual, but back to global vars issue, for a > test I defined just a global counter variable, so a global C variable, right ? > and created new function > inside siptrace module, so every time a siptrace function is called I > also call this function and do counter ++. since counter is defined > outside of the function, it should be defined as global variable, so > I've outputed with LM_INFO value of counter and it's always 1, sometime > it gets pass that value, but on the next call it's 1 again. It is the same processes ? as the variable will has independent values in each processes (check the pid in the log message) > Perhaps I'm > thinking wrong and siptrace module is not having it's own fork, but > instead loads inside other forks? That would explain this behaviour. > no, the idea is that the siptrace module code is running in multiple processes (in opensips worker processes). > If that is the case, what would you suggest? I would then need to use > interprocess communication, perhaps I could reuse something from opensips? > use the shared memory to create at startup a variable to be shared between all procs. Regards, Bogdan > Best regards, > > Josip > > Bogdan-Andrei Iancu wrote: > >> Hi Josip, >> >> Josip Djuricic wrote: >> >>> Hi, >>> >>> one probably stupid question, I'm customizing siptrace module further, >>> so I am adding queue for db writing, in case we loose db connectivity >>> and threads for popping the queue and writing to db. >>> >>> >> why don't you use the new db_virtual module with a failover >> configuration: define a new virtual db connection that has behind a >> primary mysql conn and a secondary (failover only) flatstore/dbtext >> conn. So, if DB fails, you will start writing to a local file. >> >>> Written almost everything, but just to be sure, if I use global variable >>> for linked list, will they keep the values until opensips ends, or will >>> they always be reinitialized, because for test purposes I defined >>> counter but it's always initialized to default value. >>> >>> >> To be honest I do not advices using thread in current opensips as you >> have multiple processes already. And the combination of threads and >> processes may be unpredictable. >> Anyhow, regarding your question - the global vars are init only at >> startup time - but note that "global" is as visibility in the code and >> not global "in all processes". Each process will have its own copy of >> the var. >> >> Regards, >> Bogdan >> >> > > > ___ > Users mailing list > Users@lists.opensips.org > http://lists.opensips.org/cgi-bin/mailman/listinfo/users > > -- Bogdan-Andrei Iancu www.voice-system.ro ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users
Re: [OpenSIPS-Users] global variables
In this case we can forget global c variable. I'm thinking about this solution, building custom module, that will start as a single process (one fork), and siptrace will be putting all the data on fifo queue (inside of shared memory) instead of db, and then this new module will take data from queue and put it in db. Of-course I could use virtual-db also. Best regards, Josip On Fri, 2010-03-12 at 12:59 +0200, Bogdan-Andrei Iancu wrote: > Hi Josip, > > Josip Djuricic wrote: > > Sorry I missed this email, > > > > I'll think about using db_virtual, but back to global vars issue, for a > > test I defined just a global counter variable, > so a global C variable, right ? > > and created new function > > inside siptrace module, so every time a siptrace function is called I > > also call this function and do counter ++. since counter is defined > > outside of the function, it should be defined as global variable, so > > I've outputed with LM_INFO value of counter and it's always 1, sometime > > it gets pass that value, but on the next call it's 1 again. > It is the same processes ? as the variable will has independent values > in each processes (check the pid in the log message) > > Perhaps I'm > > thinking wrong and siptrace module is not having it's own fork, but > > instead loads inside other forks? That would explain this behaviour. > > > no, the idea is that the siptrace module code is running in multiple > processes (in opensips worker processes). > > If that is the case, what would you suggest? I would then need to use > > interprocess communication, perhaps I could reuse something from opensips? > > > use the shared memory to create at startup a variable to be shared > between all procs. > > Regards, > Bogdan > > Best regards, > > > > Josip > > > > Bogdan-Andrei Iancu wrote: > > > >> Hi Josip, > >> > >> Josip Djuricic wrote: > >> > >>> Hi, > >>> > >>> one probably stupid question, I'm customizing siptrace module further, > >>> so I am adding queue for db writing, in case we loose db connectivity > >>> and threads for popping the queue and writing to db. > >>> > >>> > >> why don't you use the new db_virtual module with a failover > >> configuration: define a new virtual db connection that has behind a > >> primary mysql conn and a secondary (failover only) flatstore/dbtext > >> conn. So, if DB fails, you will start writing to a local file. > >> > >>> Written almost everything, but just to be sure, if I use global variable > >>> for linked list, will they keep the values until opensips ends, or will > >>> they always be reinitialized, because for test purposes I defined > >>> counter but it's always initialized to default value. > >>> > >>> > >> To be honest I do not advices using thread in current opensips as you > >> have multiple processes already. And the combination of threads and > >> processes may be unpredictable. > >> Anyhow, regarding your question - the global vars are init only at > >> startup time - but note that "global" is as visibility in the code and > >> not global "in all processes". Each process will have its own copy of > >> the var. > >> > >> Regards, > >> Bogdan > >> > >> > > > > > > ___ > > Users mailing list > > Users@lists.opensips.org > > http://lists.opensips.org/cgi-bin/mailman/listinfo/users > > > > > > ___ Users mailing list Users@lists.opensips.org http://lists.opensips.org/cgi-bin/mailman/listinfo/users