From: SourceForge.net <no...@so...> - 2007-11-26 18:56:21
|
Patches item #1838900, was opened at 2007-11-26 13:56 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312694&aid=1838900&group_id=12694 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Jeffrey Magder (jmagder) Assigned to: Nobody/Anonymous (nobody) Summary: Add support for multi-threaded event driven sub-agents. Initial Comment: Summary: Add support for multi-threaded event driven sub-agents. Motivation: I was working on a project that required MIB Tables to be added, removed, and updated, in response to external events, while servicing SNMP requests. Since these external events could be frequent, polling was not an option. Therefore I needed a multi-threaded subagent that could simultaneously listen for both non-snmp and snmp events. The problem was that without polling, there was no way to guarantee that a table wouldn't be removed or updated while it was being read from in another thread. What this patch does: This patch introduces some changes allowing one to write a multi-threaded sub-agent. To support this, the changes introduce two new callbacks: 1) SNMPD_CALLBACK_GRAB_LOCK 2) SNMPD_CALLBACK_RELEASE_LOCK These callbacks are meant to grab and release a mutex, shared between all threads in the subagent. The SNMPD_CALLBACK_GRAB_LOCK callback is called just before: 1) The library processes any requests. (via snmp_read()) 2) The library runs any alarms. (via run_alarms()) 3) The library checks for any outstanding agent requests. (via netsnmp_check_outstanding_agent_requests()) The SNMPD_CALLBACK_RELEASE_LOCK callback is called just after finishing one of the above requests. If you want your sub-agent to be multi-threaded, then you must register a function to grab and release a mutex, shared between all threads, under the two new callbacks listed above. Doing so will allow the net-snmp libraries to let you know when they have work to do involving data-structures your may want to modify. It is critical that before you modify any structures (ie adding/removing tables and table structures under different contexts for example) that you try to grab the same blocking mutex as per the callbacks above. You must also release these mutexes when you are finished adding/removing data to/from a table. The above was tested in a subagent in which 300,000 table additions and removals occurred in a 20 hour period under different contexts, while three simultaneous 'snmpwalks' and 'snmptables' were repeated without pause. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=312694&aid=1838900&group_id=12694 |