I see there is a new SQLops function sql_query_async that has been added in 4.2 (I believe?).
Is there a good way to perform database insert using version 4.0?
Using mysql
Thanks! -dan
On 02/16/2016 11:34 AM, Daniel W. Graham wrote:
Is there a good way to perform database insert using version 4.0?
You mean to do so asynchronously? Or just insert? If the latter, sql_query(). :-)
If the former, try:
loadmodule "rtimer" loadmodule "mqueue"
modparam("rtimer", "timer", "name=insert_writer;interval=10u;mode=1") modparam("rtimer", "exec", "timer=insert_writer;route=DO_INSERT")
modparam("mqueue", "mqueue", "name=insert_queue")
route { ...
mq_add("insert_queue", "insert_stmt", "INSERT INTO tbl (col1, col2, ... colN) VALUES (val1, ... valN)"); }
route[DO_INSERT] { while(mq_fetch("insert_queue") { $var(stmt) = $mqv(insert_queue);
sql_query("handle", "$var(stmt)", "res"); sql_result_free("res");
mq_pv_free("insert_queue"); } }
-- Alex
Well I assume either way would work, is there that big of performance hit by using sql_query?
Thanks for the info on the asyncronous route.
-----Original Message----- From: sr-users [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of Alex Balashov Sent: Tuesday, February 16, 2016 4:06 PM To: sr-users@lists.sip-router.org Subject: Re: [SR-Users] Database Insert
On 02/16/2016 11:34 AM, Daniel W. Graham wrote:
Is there a good way to perform database insert using version 4.0?
You mean to do so asynchronously? Or just insert? If the latter, sql_query(). :-)
If the former, try:
loadmodule "rtimer" loadmodule "mqueue"
modparam("rtimer", "timer", "name=insert_writer;interval=10u;mode=1") modparam("rtimer", "exec", "timer=insert_writer;route=DO_INSERT")
modparam("mqueue", "mqueue", "name=insert_queue")
route { ...
mq_add("insert_queue", "insert_stmt", "INSERT INTO tbl (col1, col2, ... colN) VALUES (val1, ... valN)"); }
route[DO_INSERT] { while(mq_fetch("insert_queue") { $var(stmt) = $mqv(insert_queue);
sql_query("handle", "$var(stmt)", "res"); sql_result_free("res");
mq_pv_free("insert_queue"); } }
-- Alex
-- Alex Balashov | Principal | Evariste Systems LLC 303 Perimeter Center North, Suite 300 Atlanta, GA 30346 United States
Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
On 02/16/2016 04:27 PM, Daniel W. Graham wrote:
Well I assume either way would work, is there that big of performance hit by using sql_query?
That depends on how long the INSERT statement takes to return. :-) In principle, it shouldn't be a big deal.
sql_query_async() is just a wrapper around something very similar to the mqueue/rtimer example I gave in the previous post. It's just more streamlined.
As far as whether there's a performance hit, that's a complex discussion. Any external I/O wait incurs some delay, but whether it's significant or whether it's worth doing anything about it is hard to say.
As it happens, I just wrote an article on this topic last night:
http://blog.csrpswitch.com/tuning-kamailio-for-high-throughput-and-performan...
-- Alex
Ok, just making sure I was on the same page :)
Thanks for the link to the article, looks like a good read!
Much appreciated, -dan
-----Original Message----- From: sr-users [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of Alex Balashov Sent: Tuesday, February 16, 2016 4:31 PM To: sr-users@lists.sip-router.org Subject: Re: [SR-Users] Database Insert
On 02/16/2016 04:27 PM, Daniel W. Graham wrote:
Well I assume either way would work, is there that big of performance hit by using sql_query?
That depends on how long the INSERT statement takes to return. :-) In principle, it shouldn't be a big deal.
sql_query_async() is just a wrapper around something very similar to the mqueue/rtimer example I gave in the previous post. It's just more streamlined.
As far as whether there's a performance hit, that's a complex discussion. Any external I/O wait incurs some delay, but whether it's significant or whether it's worth doing anything about it is hard to say.
As it happens, I just wrote an article on this topic last night:
http://blog.csrpswitch.com/tuning-kamailio-for-high-throughput-and-performan...
-- Alex
-- Alex Balashov | Principal | Evariste Systems LLC 303 Perimeter Center North, Suite 300 Atlanta, GA 30346 United States
Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
_______________________________________________ SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users