# Task processor overload

**URL:** <https://community.asterisk.org/t/task-processor-overload/89756>\
**Category:** Asterisk Support\
**Created:** [August 27, 2021, 9:45pm UTC](https://community.asterisk.org/t/task-processor-overload/89756 "2021-08-27T21:45:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [August 27, 2021, 9:45pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/1 "2021-08-27T21:45:53Z")

</div>

I’ve been getting 503 responses to REGISTER requests from phones, and looking at the source code, the only way that could happen is task processor overload (pjsip\_distributor.c). I found that these log messages appear for almost every call:

```auto
WARNING[27858][C-00000001] taskprocessor.c: The 'stasis/m:manager:core-00000007' task processor queue reached 3000 scheduled tasks.
WARNING[25160][C-00000008] taskprocessor.c: The 'stasis/p:endpoint:PJSIP/XXX-0000001c' task processor queue reached 500 scheduled tasks.

```

The dialplan is rather complex, so I suspected that the first message is caused by excessive VarSet and Newexten events. Indeed, after I disabled their creation in source and recompiled, the first warning disappeared.

I have no clue about the second, though, and I would appreciate some guidance. If I dial one PJSIP endpoint from another, the warning usually appears for both, but more often for the calling one.

---

<div class="post-metadata">

**Author:** ![kharwell](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/kharwell/32/1924_2.png) [@kharwell](https://community.asterisk.org/u/kharwell)\
**Post date:** [September 2, 2021, 5:55pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/2 "2021-09-02T17:55:44Z")

</div>

If you haven’t seen it already [this post](https://www.asterisk.org/asterisk-task-processor-queue-size-warnings/) has some good, and still applicable information about taskprocessors and queue size warnings. .

Note the ‘p’ in:

> stasis/p:endpoint:PJSIP/XXX-0000001c

That means it’s “pooled”, so adjusting the stasis threadpool might potentially help some. From the [blog post](https://www.asterisk.org/asterisk-task-processor-queue-size-warnings/):

> You can adjust the thread pool parameters for PJSIP and stasis task processors. The PJSIP thread pool is configured in [pjsip.conf](https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Configuration_res_pjsip). The stasis thread pool is configured in [stasis.conf](https://wiki.asterisk.org/wiki/display/AST/Asterisk+13+Configuration_stasis).

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 7:52am UTC](https://community.asterisk.org/t/task-processor-overload/89756/3 "2021-09-03T07:52:05Z")

</div>

Thanks for the reply. I’ve played with the thread pool settings already, but doesn’t seem to make a difference. We are talking about a system with a single active call. I am not doing anything fancy, one PJSIP endpoint dials another. Does that really require 500+ tasks? The fact that developers put this warning tells me that reaching 500 scheduled tasks is not a normal or desirable situation, so I would like to know what could theoretically cause it. Is there some way I can debug it? I can never catch these tasks with “core show taskprocessors”.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 10:10am UTC](https://community.asterisk.org/t/task-processor-overload/89756/4 "2021-09-03T10:10:00Z")

</div>

After further investigation, the second warning is also caused by dialplan complexity. My mistake was thinking that PJSIP endpoint task processor only deals with SIP signalling, but apparently it deals with everything that happens on the channel. I keep call routing table in Postgres database and process rules in dialplan, which generates extraordinary amount of tasks. I am guessing Varset and Newexten are again the culprits.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 1:18pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/5 "2021-09-03T13:18:51Z")

</div>

OK, after more digging, I’ve encountered the option “hide\_messaging\_ami\_events”, which is supposed to supress Newexten and Varset events, and even defaults to “yes” in v18. However, even if I explicitly set it in asterisk.conf, I am still getting those events over AMI. Am I not understanding something?

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [September 3, 2021, 1:23pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/6 "2021-09-03T13:23:12Z")

</div>

That option has no impact on those events for calls. It is for the text messaging channel, not for regular channels.

The stasis.conf configuration file can be used to stop the creation of internal Stasis messages for different types, such as the ones you mentioned.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 1:38pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/7 "2021-09-03T13:38:55Z")

</div>

Thanks. I am guessing ast\_channel\_snapshot\_type is for Newexten? I’ve tried disabling that, but then I get:

[2021-09-03 15:35:26.926] NOTICE[29403] cdr.c: CDR simple logging enabled.  
[2021-09-03 15:35:26.927] ERROR[29403] cel.c: Failed to register for Stasis messages  
[2021-09-03 15:35:26.936] ERROR[29403] loader.c: \*\*\* Failed to load module cel  
[2021-09-03 15:35:26.936] ERROR[29403] asterisk.c: Module initialization failed. ASTERISK EXITING!

I don’t need CEL, can I disable it alltogether?

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [September 3, 2021, 1:40pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/8 "2021-09-03T13:40:13Z")

</div>

Disabling ast\_channel\_snapshot\_type would end poorly. It’s used by a lot of core things. If CEL is disabled in cel.conf then it will not subscribe to messages.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 1:41pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/9 "2021-09-03T13:41:55Z")

</div>

OK, so I can’t disable Newexten without compromising Asterisk stability?

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [September 3, 2021, 1:43pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/10 "2021-09-03T13:43:21Z")

</div>

The creation of the internal message, no. There are filters that can be done in manager.conf if you’re actually using AMI so it at least doesn’t go out AMI.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [September 3, 2021, 1:52pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/11 "2021-09-03T13:52:49Z")

</div>

As an observation, I tried to find documentation on Aterisk stasis messaging, but it seems to be missing all but an extremely high level overview and stateless descriptions of a few APIs, I couldn’t find any information, less detailed than the source code, about the internal structure, and in particular why it needs task processor threads, or on the ways that the different components of Asterisk communicate using it, including the naming structures for the various queues that can overflow.

Have I overlooked something, or are there some modules that are good examples of its use both as publisher and subscriber, which aren’t a mega byte of source code?

We seem to be more and more reports of these overloads, but it is difficult to respond to them at any more than a very high level, namely that they are only warnings and symptomatic of other problems, and I haven’t really seen any replies that specifically identify the bottlenecks involved.

---

<div class="post-metadata">

**Author:** ![jcolp](https://sea1.discourse-cdn.com/asterisk/user_avatar/community.asterisk.org/jcolp/32/8848_2.png) [@jcolp](https://community.asterisk.org/u/jcolp)\
**Post date:** [September 3, 2021, 1:57pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/12 "2021-09-03T13:57:11Z")

</div>

I don’t know of anything precisely, but stasis itself isn’t overly complex. You create a message, you publish it to a topic, each subscriber receives that message. A subscriber can either receive the message using its own dedicated thread or a thread out of a pool. If the subscriber can’t process things fast enough (messages are published faster than being consumed), then the queue of messages (they’re ordered) grows and you get a warning.

The naming of things is to a degree arbitrary. In developer mode, however, there are stasis CLI commands (stasis show and TAB to auto complete) to allow you to inspect things further which can provide better insight.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 2:55pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/13 "2021-09-03T14:55:30Z")

</div>

I guess the conclusion is that having a dialplan with a lot of processing is unfeasible. The solution is to offload the critical parts to FastAGI?

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [September 3, 2021, 3:01pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/14 "2021-09-03T15:01:35Z")

</div>

One of the core users of Asterisk, FreePBX has huge dialplans.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 3:11pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/15 "2021-09-03T15:11:13Z")

</div>

I know, but not as huge as this. Mine actually has less lines than theirs, but there is a lot of complex processing in a loop. A single call generates 40k - 50k scheduled tasks.

---

<div class="post-metadata">

**Author:** ![sedwards](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sedwards](https://community.asterisk.org/u/sedwards)\
**Post date:** [September 3, 2021, 4:27pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/16 "2021-09-03T16:27:30Z")

</div>

> [@niksa](#):
>
> there is a lot of complex processing in a loop. A single call generates 40k - 50k scheduled tasks.

This sounds like ‘AGI/AMI territory’ to me. ‘Dialplan’ is fine for routing calls and simple call flow, but when I hear ‘complex’ and ‘lots of stuff’ I think it’s time for a real programming language – features, debugging, real syntax checking with real error messages, etc.

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 4:43pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/17 "2021-09-03T16:43:25Z")

</div>

I’ve written it in AEL, which at least tries to be a programming language. I didn’t have much trouble with AEL itself, and everything works. It just didn’t occur to me that sheer number of darn Newextens is going to be a problem.

---

<div class="post-metadata">

**Author:** ![sedwards](https://avatars.discourse-cdn.com/v4/letter/s/838e76/32.png) [@sedwards](https://community.asterisk.org/u/sedwards)\
**Post date:** [September 3, 2021, 6:42pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/18 "2021-09-03T18:42:06Z")

</div>

> [@niksa](#):
>
> I’ve written it in AEL, which at least tries to be a programming language

AEL is a step up, but a misplaced semi-colon or brace and half your dialplan disappears with no or misleading warnings.

You also still have limited functionality, no debugging, obtuse quoting, no libraries, …

---

<div class="post-metadata">

**Author:** ![niksa](https://avatars.discourse-cdn.com/v4/letter/n/f0a364/32.png) [@niksa](https://community.asterisk.org/u/niksa)\
**Post date:** [September 3, 2021, 7:18pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/19 "2021-09-03T19:18:38Z")

</div>

> [@sedwards](#):
>
> You also still have limited functionality, no debugging, obtuse quoting, no libraries, …

Yeah, tell me about it. Still, I could have lived with it, were it not for this issue.

---

<div class="post-metadata">

**Author:** ![david551](https://avatars.discourse-cdn.com/v4/letter/d/3bc359/32.png) [@david551](https://community.asterisk.org/u/david551)\
**Post date:** [September 3, 2021, 7:41pm UTC](https://community.asterisk.org/t/task-processor-overload/89756/20 "2021-09-03T19:41:10Z")

</div>

I guess the problem is that you are doing a very long run of processing without blocking, and in the short term all the other CPU cores are busy, so not all the subscribers can read out their queues, or the subscribers are blocking, so they can’t read out their full queue.

[Next page](https://community.asterisk.org/t/task-processor-overload/89756.md?page=2)
