[issue37355] SSLSocket.read does a GIL round-trip for every 16KB TLS record

2021-04-19 Thread Josh Snyder


Change by Josh Snyder :


--
keywords: +patch
pull_requests: +24203
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/25478

___
Python tracker 
<https://bugs.python.org/issue37355>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37355] SSLSocket.read does a GIL round-trip for every 16KB TLS record

2019-06-20 Thread Josh Snyder


New submission from Josh Snyder :

Background:

SSLSocket.read drops the GIL and performs exactly one successful call to  
OpenSSL's `SSL_read`, whose documentation states "At most the contents of one 
record will be returned". TLS records are at most 16KB, so high throughput 
(especially multithreaded) TLS reception can become bottlenecked on the GIL.

Proposal:

For non-blocking sockets, call SSL_read in a loop until the user-supplied limit 
is reached or no bytes are available on the socket. I don't know of a way to 
safely improve performance for blocking sockets.

Initial testing:

I performed initial testing using 32 threads pinned to 16 cores, downloading 
and re-assembling a single 140270MB file from a "real world" TLS sender. This 
resulted in a 4x increase in throughput, a 6.6x reduction in voluntary context 
switches, a 3.5x reduction in system time. User time did increase by 43%, so 
the overall reduction in CPU usage was only 2.67x.

 before after
 wall clock time (s):29.637 7.116
 user time (s)  : 8.79312.584
 system time (s):   105.11830.010
 user + system time (s) :   113.91142.594
 cpu utilization (%):   384   599 
 voluntary switches : 1,653,065   248,484
 speed (MB/s)   :  4733 19712

My git branch (currently a draft) is at 
https://github.com/hashbrowncipher/cpython/commits/faster_tls

--
assignee: christian.heimes
components: SSL
messages: 346156
nosy: christian.heimes, josnyder
priority: normal
severity: normal
status: open
title: SSLSocket.read does a GIL round-trip for every 16KB TLS record
type: performance

___
Python tracker 
<https://bugs.python.org/issue37355>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35046] logging.StreamHandler performs two syscalls when one would do

2018-10-22 Thread Josh Snyder


Change by Josh Snyder :


--
keywords: +patch
pull_requests: +9381
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue35046>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue35046] logging.StreamHandler performs two syscalls when one would do

2018-10-22 Thread Josh Snyder


New submission from Josh Snyder :

logging.StreamHandler contains the following code:

stream.write(msg)
stream.write(self.terminator)
stream.flush()

When sys.stderr (or whatever other stream) is unbuffered, this results in two 
system calls and allows log records from different processes to concatenate on 
the same line in the output stream (followed by multiple newlines). This issue 
is new in Python 3.7, as stdout and stderr became "truly unbuffered" (cf. 
#30404).

As a simple solution, I believe the following would fix the issue and also be 
backward compatible:

stream.write(msg + self.terminator)
stream.flush()

--
messages: 328269
nosy: josnyder
priority: normal
severity: normal
status: open
title: logging.StreamHandler performs two syscalls when one would do
type: behavior
versions: Python 3.7

___
Python tracker 
<https://bugs.python.org/issue35046>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32475] Add ability to query number of buffered bytes available on buffered I/O

2018-06-26 Thread Josh Snyder


Josh Snyder  added the comment:

I've opened PR #7947 with another approach to this issue.

In my use-case, an HTTP client makes a request and uses buffered I/O to parse 
the response headers. I would like to hand off the response socket to an 
extension module for use with raw I/O syscalls. The BufferedReader likely 
already contains some of the response body, which I would like to access before 
handing the socket off.

--
nosy: +josnyder

___
Python tracker 
<https://bugs.python.org/issue32475>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32475] Add ability to query number of buffered bytes available on buffered I/O

2018-06-26 Thread Josh Snyder


Change by Josh Snyder :


--
pull_requests: +7556
stage:  -> patch review

___
Python tracker 
<https://bugs.python.org/issue32475>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com