Comments (6)
I think the problem lies on this code:
sseclient.py:58
def _event_complete(self):
return re.search(end_of_field, self.buf) is not None
def __iter__(self):
return self
def __next__(self):
while not self._event_complete():
try:
nextchar = next(self.resp_iterator)
self.buf += nextchar
except (StopIteration, requests.RequestException):
time.sleep(self.retry / 1000.0)
self._connect()
# The SSE spec only supports resuming from a whole message, so
# if we have half a message we should throw it out.
head, sep, tail = self.buf.rpartition('\n')
self.buf = head + sep
continue
from marathon-python.
Half a million times eh? :(
Surely there is a more efficient way to see if EOF is in the buffer!
from marathon-python.
robj@robj-yelp-mb: % python -m timeit -n 10000 -s "import re; x='\r\n\r\n'; y='\r\r'; z='\n\n'; s='helloab'*100000" "x in s or y in s or z in s"
10000 loops, best of 3: 2.15 msec per loop
robj@robj-yelp-mb:% python -m timeit -n 10000 -s "import re; end_of_field = re.compile(r'\r\n\r\n|\r\r|\n\n'); s='helloab'*100000" "end_of_field.search(s)"
10000 loops, best of 3: 5.69 msec per loop
maybe I've missed something here, but seems using python's built in string matching would be faster? I took the regex from here
from marathon-python.
@solarkennedy Yep !
@Rob-Johnson Yep !
The caveat is that Marathon actually returns all tasks from all apps bundled into the event data so in my case where I got 200 tasks you can imagine the size of the buffer.
If we count 1 byte per character, 500k characters (or iterations of 1 char) would be...500kb of data ! OMFG !
In marathon's sse case, the last character will always be the EOF so the code from sseclient would have to iterate over the whole buffer trying to find it until it finally encounters it.
It would be even easier to read the whole buffer and use a simple (yet powerfull) string search with ".find()" or "in".
Ill try to post some benchmarks here, but I think it will be magnitudes faster than 1/2 million searches using regexp.
from marathon-python.
I solved this problem on #143 =]
from marathon-python.
@migueleliasweb I've already made a pull-request to sseclient which solves this problem:
https://bitbucket.org/btubbs/sseclient/pull-requests/9/response-readline/diff
from marathon-python.
Related Issues (20)
- File-based secrets aren't supported
- Support marathon pods api HOT 1
- Lack of support for container.networks HOT 1
- from_json always creates mappings with host port
- SSE SSL authentication not supported HOT 2
- Travis tests are broken
- Client should be updated to follow /v2/events redirection responses
- Add asyncio support HOT 6
- Support custom fields in application definition HOT 1
- Add support for proxies
- from_json with None crashes event stream
- Downloading Log For App HOT 1
- MarathonClient().scale_group does not support force parameter
- support status query parameter for "/v2/tasks"
- about view one instance app logs real time HOT 2
- List apps returns TypeError HOT 7
- unexpected keyword argument 'tasks_stats' with client.get_app('app_id', embed_task_stats=True) HOT 1
- Unexpected Keyword argument enforce_role on marathon.get_group
- New Release? HOT 1
- drop use_2to3 command from setup.py
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from marathon-python.