Comments (7)
@alexdej Hi! Thanks for raising this issue! Indeed this is a performance problem and we should reuse the underlying TCP connection/socket.
Currently, using json_request you can send push notifications in bulks of 1000, so if you have 1 million tokens you would open 1000 TCP connections to the GCM server.
I've just tested with a few million notifications something along the lines of: https://github.com/mnemonicflow/python-gcm/commit/00a93d69288bc786e30d43df89ef271ac54117ce which should be a good starting point, although this means forcing the clients of the library to use a context manager and existing clients need to update their code.
with GCM(API_KEY) as gcm:
response = gcm.json_request(registration_ids=registration_ids, data=notification,
collapse_key='xyz',
priority='high',
restricted_package_name="com.mycompany.myawesomeapp,
delay_while_idle=True,
dry_run=False)
But I think would be better to add another level of indirection and run the cleanup code inside the GCM object by creating a static session object wrapper using the https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager decorator or similar.
Regarding thread safety, I think it should be handled by the client of the library and maybe add an option to the GCM object to specify if you want connection reuse or not.
from python-gcm.
Great! Your suggestion would work fine for our case, though I agree you might want to make the new behavior optional to avoid changing existing clients (and to preserve thread safety of gcm library by default).
from python-gcm.
👍 on reusing connections. @mnemonicflow your suggestion only works if the data is the same for all recipients, right? If the data is unique for everyone you'd have to call gcm.json_request()
once per recipient.
from python-gcm.
@tgwizard Yes, the data is the same for all recipients you pass in the registration_ids parameter. If you want to send different data for different recipients you have to group the recipients (preferrably in bulks of 1000) and pass the specific data you want to send to them in a different json_request call.
The underlying TCP connection is still reused due to the session object but as the documentation says http://docs.python-requests.org/en/latest/user/advanced/ the data is NOT.
"Note, however, that method-level parameters will not be persisted across requests, even if using a session."
Method level parameters refers to the parameters of the .post, .get, .put, etc. methods of the requests.Session() object
from python-gcm.
Thanks for the response @mnemonicflow. The session, and TCP connection, reuse will only be enabled when #96 being merged, as now there's a call to requests.post
, which creates new sessions for every call. Or am I missing something?
from python-gcm.
@tgwizard Yes! #96 got merged in develop branch https://github.com/geeknam/python-gcm/tree/develop
from python-gcm.
Cool, thank you!
from python-gcm.
Related Issues (20)
- Help getting started with python-gcm HOT 1
- No support for setting up priority for a given message? HOT 4
- Permission denied error while using send_topic_message() in a GAE environment
- GCM should handle requests exceptions
- if occur retry send request, response info would be wrong (not contain response info of previous request) ?!
- Compatibility with Firebase Cloud Messaging (FCM) ? HOT 4
- Pass GCM (Now FCM) responses to object outputs and not just to the debugger
- request fail HOT 2
- does not handle mixed data & notification messages HOT 1
- Update documentation to include instructions for running unit test cases. HOT 1
- Use nosetest and tox setup to locally run the unit test cases and generate coverage report
- Update to support Notification messages in the FCM payload HOT 2
- Set requests timeout HOT 4
- How to create a vaild GCM API_KEY(sender) and registration token for client(receiver)
- Consider adding deprecation/unmaintained warning to Readme
- DepShield Deprecation Notice
- Sending a message to topic HOT 1
- Not able to access data in service worker HOT 1
- Multiple Resends HOT 7
- python gcm also for IOS HOT 2
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 python-gcm.