Skip to content

Commit 3b2c522

Browse files
committed
Rewrite tips for Sans-I/O integration.
1 parent d248160 commit 3b2c522

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

docs/howto/sansio.rst

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -302,21 +302,24 @@ Tips
302302
Serialize operations
303303
....................
304304

305-
The Sans-I/O layer expects to run sequentially. If your interact with it from
306-
multiple threads or coroutines, you must ensure correct serialization. This
307-
should happen automatically in a cooperative multitasking environment.
305+
The Sans-I/O layer is designed to run sequentially. If you interact with it from
306+
multiple threads or coroutines, you must ensure correct serialization.
308307

309-
However, you still have to make sure you don't break this property by
310-
accident. For example, serialize writes to the network
311-
when :meth:`~protocol.Protocol.data_to_send` returns multiple values to
312-
prevent concurrent writes from interleaving incorrectly.
308+
Usually, this comes for free in a cooperative multitasking environment. In a
309+
preemptive multitasking environment, it requires mutual exclusion.
313310

314-
Avoid buffers
315-
.............
311+
Furthermore, you must serialize writes to the network. When
312+
:meth:`~protocol.Protocol.data_to_send` returns several values, you must write
313+
them all before starting the next write.
316314

317-
The Sans-I/O layer doesn't do any buffering. It makes events available in
315+
Minimize buffers
316+
................
317+
318+
The Sans-I/O layer doesn't perform any buffering. It makes events available in
318319
:meth:`~protocol.Protocol.events_received` as soon as they're received.
319320

320-
You should make incoming messages available to the application immediately and
321-
stop further processing until the application fetches them. This will usually
322-
result in the best performance.
321+
You should make incoming messages available to the application immediately.
322+
323+
A small buffer of incoming messages will usually result in the best performance.
324+
It will reduce context switching between the library and the application while
325+
ensuring that backpressure is propagated.

0 commit comments

Comments
 (0)