You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid using pb internals for datastore on App Engine #298
Just a random note about proto usage:
If you plan to let users run gcloud-python in the App Engine python runtime, proto access is
really slow (I believe because of the sandbox). I would limit proto access to serialization
and deserialization only.
and
Not 100% sure, but I think it uses a C proto library so it goes outside the process boundary.
@pcostell I'm not sure your previous comments are relevant to gcloud. I just created a test application and the proto used is via the external protobuflibrary, not the proto libraries provided in App Engine.
I added a debug print to check Entity.save() times in a single request and got:
0.197650 seconds
0.113310 seconds
0.169830 seconds
I was worried this was slow so did the same locally with the version on PyPI (0.3.0) and got similar times:
1.152835 seconds (app was cold)
0.233535 seconds
0.359164 seconds
0.217317 seconds
ISTM the App Engine speed-up is due to the fast-path between the App Engine app and the Cloud Datastore machines.
UPDATE: I'm fairly certain Patrick was referring to google.net.proto and google.net.proto2 as the libraries to avoid using. I checked to make sure we don't ever import from proto libraries included in GAE.
SECOND UPDATE: I broke down Entity.save() into lower and lower level component pieces until the network was the only thing left. The times of each show that the impact of using the protobuflibrary is negligible.
Awesome, good to know. Something that may be important: The reason GAE protos have slow access is that they use the C++ library, which requires a process boundary cross. This is used instead of a pure python library because serialization and deserialization is much faster in C++ than in python. In may be worthwhile to still minimize proto access in order to minimize SWIG-code entry points when users do have the C++ libraries (running on VMs or if GAE adds google.protobuf to the runtime).
Currently, when using the externally available protobuf library on App Engine, it is using the python-only version of the protobuf library (it's impossible to upload a C library to the python runtime). However, once we are able to get the external C library into the App Engine runtime it will start using the C version instead of the python version. The C version has faster encode/decode times however you do pay a penalty when accessing protocol buffer fields because it has to cross a process boundary. We saw this in NDB's Key implementation which tried to store everything internally in protobuf rather than storing the fields as native python types.
I went through and it looks like you only access the protobuf on serialization and deserialization, which is perfect, so I'm leaving this as closed.
Activity
dhermes commentedon Dec 30, 2014
Currently digging into https://www.simonmweber.com/2013/06/18/python-protobuf-on-app-engine.html to see what I can find out.
dhermes commentedon Dec 30, 2014
@pcostell I'm not sure your previous comments are relevant to
gcloud. I just created a test application and the proto used is via the externalprotobuflibrary, not the proto libraries provided in App Engine.I added a debug print to check
Entity.save()times in a single request and got:I was worried this was slow so did the same locally with the version on PyPI (0.3.0) and got similar times:
ISTM the App Engine speed-up is due to the fast-path between the App Engine app and the Cloud Datastore machines.
UPDATE: I'm fairly certain Patrick was referring to
google.net.protoandgoogle.net.proto2as the libraries to avoid using. I checked to make sure we don't ever import from proto libraries included in GAE.SECOND UPDATE: I broke down
Entity.save()into lower and lower level component pieces until the network was the only thing left. The times of each show that the impact of using theprotobuflibrary is negligible.dhermes commentedon Dec 30, 2014
@silvolu @tseaver FYI
gcloudworks just fine deployed in App Engine.tseaver commentedon Dec 31, 2014
Great analysis!
pcostell commentedon Jan 4, 2015
Awesome, good to know. Something that may be important: The reason GAE protos have slow access is that they use the C++ library, which requires a process boundary cross. This is used instead of a pure python library because serialization and deserialization is much faster in C++ than in python. In may be worthwhile to still minimize proto access in order to minimize SWIG-code entry points when users do have the C++ libraries (running on VMs or if GAE adds google.protobuf to the runtime).
dhermes commentedon Jan 5, 2015
Luckily the
protobuflibrary only uses C-code from the standard library. As @tseaver pointed out earlier today,structis plenty fast.I analyzed the imports, and the only imports from outside the library are:
pcostell commentedon Jan 12, 2015
Currently, when using the externally available protobuf library on App Engine, it is using the python-only version of the protobuf library (it's impossible to upload a C library to the python runtime). However, once we are able to get the external C library into the App Engine runtime it will start using the C version instead of the python version. The C version has faster encode/decode times however you do pay a penalty when accessing protocol buffer fields because it has to cross a process boundary. We saw this in NDB's Key implementation which tried to store everything internally in protobuf rather than storing the fields as native python types.
I went through and it looks like you only access the protobuf on serialization and deserialization, which is perfect, so I'm leaving this as closed.
tseaver commentedon Jan 12, 2015
@pcostell we just recently dropped the "long-lived protobuf" inside Query: glad that helps.
32 remaining items
chore: update templated files (#298)
chore(deps): update all dependencies (#298)
chore(deps): update all dependencies (#298)
FIX: update minimum google-cloud-bigquery version to 1.11.1 (#298)
chore: allow release-please to make releases (#298)
fix: handle bare 'grpc.Call' in 'from_grpc_error' (#298)
fix: the unnest function lost needed type information (#298)
chore: release 1.2.0 (#338)
chore(python): update unittest workflow template (#298)
Update README.rst for Python 3.7 (#298)
Enable static type checking with pytype (#298)
samples: use flaky in tests (#298)
chore(deps): update dependency importlib-metadata to v5.2.0 (#298)
fix: preserve metadata value (#298)
chore: loosen opentelemetry dependencies (#298)