Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

investigate if we need to fix flow control #1

Closed
komuw opened this issue Jun 23, 2018 · 1 comment
Closed

investigate if we need to fix flow control #1

komuw opened this issue Jun 23, 2018 · 1 comment

Comments

@komuw
Copy link
Owner

komuw commented Jun 23, 2018

see: sanic-org/sanic#1176

@komuw
Copy link
Owner Author

komuw commented Jan 20, 2019

We are already practicing good flow control practices.
We are using[1] a streamWriter[2].
When we want to send data to SMSC, we call writer.write() followed by await wariter.drain();

naz/naz/client.py

Lines 883 to 884 in 945a568

self.writer.write(msg)
await self.writer.drain()

The documentation for streamwriter[2] .write method says;

Write data to the stream.     
This method is not subject to flow control. Calls to `.write()` should be followed by `drain()`

The documentation for streamwriter[2] .drain method says;

This is a flow control method that interacts with the underlying IO write buffer.     
When the size of the buffer reaches the high watermark,     
`drain()` blocks until the size of the buffer is drained down to the low watermark      
and writing can be resumed.           
When there is nothing to wait for, the drain() returns immediately.

When the size of the buffer reaches the high watermark, writer.drain() blocks until the size of the buffer is drained down to the low watermark and writing can be resumed.

So by doing;

naz/naz/client.py

Lines 883 to 884 in 945a568

self.writer.write(msg)
await self.writer.drain()

we are practising flow control.

The only thing we are not doing is setting our own buffer sizes. We are relying on the default buffer sizes(which I think are pretty okay).

  1. The default writer buffer sizes are:
low_buffer_watermark_in_bytes, high_buffer_watermark_in_bytes = writer.transport.get_write_buffer_limits()
(16384, 65536) # ie, 16KB and 65KB
  1. The default reader buffer sizes are, 64 KiB - [3]

ref:

  1. naz/naz/client.py

    Lines 343 to 345 in 945a568

    reader, writer = await asyncio.open_connection(
    self.smsc_host, self.smsc_port, loop=self.async_loop
    )
  2. https://docs.python.org/3/library/asyncio-stream.html#streamwriter
  3. https://docs.python.org/3/library/asyncio-stream.html#asyncio.open_connection

@komuw komuw closed this as completed Jan 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant