Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 06191d3

Browse files
authored
Merge pull request #268 from jsun-splunk/scaling-k8s
Use select.poll() for exec on linux/darwin
2 parents 4f761d3 + 18828d9 commit 06191d3

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

stream/ws_client.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
import sys
1415

1516
from kubernetes.client.rest import ApiException, ApiValueError
1617

@@ -167,8 +168,25 @@ def update(self, timeout=0):
167168
if not self.sock.connected:
168169
self._connected = False
169170
return
170-
r, _, _ = select.select(
171-
(self.sock.sock, ), (), (), timeout)
171+
172+
# The options here are:
173+
# select.select() - this will work on most OS, however, it has a
174+
# limitation of only able to read fd numbers up to 1024.
175+
# i.e. does not scale well. This was the original
176+
# implementation.
177+
# select.poll() - this will work on most unix based OS, but not as
178+
# efficient as epoll. Will work for fd numbers above 1024.
179+
# select.epoll() - newest and most efficient way of polling.
180+
# However, only works on linux.
181+
if sys.platform.startswith('linux') or sys.platform in ['darwin']:
182+
poll = select.poll()
183+
poll.register(self.sock.sock, select.POLLIN)
184+
r = poll.poll(timeout)
185+
poll.unregister(self.sock.sock)
186+
else:
187+
r, _, _ = select.select(
188+
(self.sock.sock, ), (), (), timeout)
189+
172190
if r:
173191
op_code, frame = self.sock.recv_data_frame(True)
174192
if op_code == ABNF.OPCODE_CLOSE:

0 commit comments

Comments
 (0)