What is the Context object and how many do I need?
Best Answer
-
Contexts provide the thread that polls all connected sockets, representing the
select()
loop and socket processing logic for the API.As a general rule, one context per process fits most use-cases. Since even requirements for connecting to multiple brokers are handled with multiple sessions.
Even in high volume use-cases, typically the network is the bottleneck and adding more contexts won't help.
That said, some scenarios where multiple contexts can help:
1. Handling very high network activity on a multi-NIC and multi-core server could benefit from parallelism across multiple select loops
2. If there is heavy processing taking place in the message callback (which is not best practice!), multiple contexts can prevent one session being blocked by the slow receive activity of another.
0
Answers
-
Contexts provide the thread that polls all connected sockets, representing the
select()
loop and socket processing logic for the API.As a general rule, one context per process fits most use-cases. Since even requirements for connecting to multiple brokers are handled with multiple sessions.
Even in high volume use-cases, typically the network is the bottleneck and adding more contexts won't help.
That said, some scenarios where multiple contexts can help:
1. Handling very high network activity on a multi-NIC and multi-core server could benefit from parallelism across multiple select loops
2. If there is heavy processing taking place in the message callback (which is not best practice!), multiple contexts can prevent one session being blocked by the slow receive activity of another.
0