1

I am trying to have a persistent connection to a third party using app engine. Specifically I am hooking into a real time bidding environment where I need to respond in under 100ms, and thus a persistent connection greatly accelerates the process.

In order to do this I am attempting to use urllib3 (if there is a better way please tell me) When my request handler's post method gets called, I want to write back out to the calling url keeping the connection open. I understand how to open a request with urllib3, but how do I persist the connection that was created when the post method on the handler was called.

At the moment I am trying:

http = urllib3.PoolManager()
r = http.request('POST', self.request.url, fields={"foo":"bar"})

But I fear I am opening an entirely new connection doing this.

Thanks, Sam

Kimvais
  • 38,306
  • 16
  • 108
  • 142
SammmyC
  • 37
  • 3
  • possible duplicate of [Persistence of urllib.request connections to a HTTP server](http://stackoverflow.com/questions/9772854/persistence-of-urllib-request-connections-to-a-http-server) – Kimvais Aug 15 '12 at 06:45
  • Close voters: not a duplicate of that question. – Wooble Aug 15 '12 at 13:54

1 Answers1

3

There is no way to achieve persistent connection to a server with AppEngine, by design every request on the app engine closes after finish sending.

The URL Fetch service does not support persistent HTTP connections. When the app accesses response data using the URLConnection object, App Engine calls the URL Fetch service to complete the request. After the response data has been accessed, the request data cannot be modified.

The app cannot set explicit connection timeouts for the request.

Shay Erlichmen
  • 31,691
  • 7
  • 68
  • 87
  • Isn't Url Fetch used only for out going? I want to persist the incoming connection and write back out on the same connection, which I thought I could use urllib3 for the outgoing. – SammmyC Aug 15 '12 at 21:35
  • Its not possible for the same reason, by the time you get the request the connection is disconnected. – Shay Erlichmen Aug 15 '12 at 22:51