自由开关被阻止

时间:2018-12-04 09:40:32

标签: c linux multithreading freeswitch

FreeSwitch软件在几天之内(〜3-5天)可以正常工作,由于FreeSwitch被阻止,因此可以接受新的来电请求!正在进行的呼叫继续其会话,它们的呼叫似乎没有受到影响,但是不接受新的呼叫。我得到了FreeSwitch快照,并在GDB中对其进行了分析。

我有601位therads,其中大多数都在等待

Thread 0x7f16bc55f700 (LWP 28544) pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185

当我在gdb中应用“线程应用所有bt”时,我看到大多数线程都试图将事件推送到队列中(switch_queue_push)

Thread 600 (Thread 0x7f16bc55f700 (LWP 28544)):
#0 pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
#1  0x00007f180cf9b87d in apr_thread_cond_wait (cond=<optimized out>, mutex=<optimized out>) at locks/unix/thread_cond.c:68
#2  0x00007f180cf92dd0 in apr_queue_push (queue=queue@entry=0x7f180db157a8, data=data@entry=0x7f16d3d5ec20) at misc/apr_queue.c:166
#3  0x00007f180cc958fb in switch_queue_push (queue=0x7f180db157a8, data=data@entry=0x7f16d3d5ec20) at src/switch_apr.c:1134
#4  0x00007f180cd17850 in switch_event_queue_dispatch_event (eventp=0x7f16bc55ec48) at src/switch_event.c:384
#5  switch_event_fire_detailed (file=file@entry=0x7f180cfb07ea "src/switch_channel.c", func=func@entry=0x7f180cfb2ba0 <__func__.18348> "switch_channel_perform_set_running_state", line=line@entry=2260, event=event@entry=0x7f16bc55ec48, user_data=user_data@entry=0x0) at src/switch_event.c:1986
#6  0x00007f180cc9f118 in switch_channel_perform_set_running_state (channel=0x7f17e3e7de00, state=CS_NEW, file=0x7f180cfbc590 "src/switch_core_state_machine.c", func=<optimized out>, line=543) at src/switch_channel.c:2260
#7  0x00007f180ccc87d0 in switch_core_session_run (session=0x7f17e3e7fd28) at src/switch_core_state_machine.c:543
#8  0x00007f180ccc36de in switch_core_session_thread (thread=<optimized out>, obj=0x7f17e3e7fd28) at src/switch_core_session.c:1629
#9  0x00007f180ccbf47d in switch_core_session_thread_pool_worker (thread=0x7f17e3e9abb0, obj=0x80) at src/switch_core_session.c:1692
#10 0x00007f180cfa1910 in dummy_worker (opaque=0x7f17e3e9abb0) at threadproc/unix/thread.c:151
#11 0x00007f180c1e0064 in start_thread (arg=0x7f16bc55f700) at pthread_create.c:309
#12 0x00007f180b8b862d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111

为什么我要得到这种状态? 任何想法,技巧和窍门将不胜感激。 问候

1 个答案:

答案 0 :(得分:0)

我已经深入研究并找到了解决方案,

您应该了解Freeswitch的“ 事件处理程序机制”以解决此问题。因为有许多生产者线程会生成事件并将其事件放入此队列,但是此机制中仅存在一个使用者线程。消费者线程(称为事件处理程序)将事件传递给所有侦听器,例如侦听适当事件的模块。

这些侦听器中的一个或多个可以阻止(通过阻止)此使用者线程,并且事件队列可能变得很满。当事件队列已满时,您的费用切换将被阻止。

有三种解决这些问题的方法:

1::在默认配置中,事件处理程序机制使用事件队列。但是,您可以通过更改使用线程解决方案 “ post_load_switch.conf ”文件中的“ events-use-dispatch = false ”值。

2 :增加使用者线程数,因为单个使用者线程不是重载freeswitch服务器的好解决方案 您可以使用“ post_load_switch.conf ”文件中的“ initial-event-threads = X ”完成操作,其中X表示初始线程数。

3 :在您的模块中,您也可以使用事件处理程序机制。当您从Freeswitch的核心获取事件时,请创建一个新线程并将其分配到您新创建的线程中,以便不等待Freeswitch的使用者线程。