Permanent / Keep-Alive HTTP Connection Using POST In Rails

Is there a way to maintain / work with persistent connection for the POST command in rails?

I would like to create an API in which my application accepts what constitutes a data stream from an external service (I write this external service, so I can be flexible in my design here). Speed ​​is critical. I need to get information from an external source at a speed of 1000+ dots per second. Talking with some computer scientists, one came up with the idea of ​​using a permanent connection, so that expensive stunt interaction was necessary to complete only once. Using a library inside an external service, I would then create several POST elements that were added to my rails application, and then process these POST elements in turn.

My understanding of the rail paradigm is that each request (POST, GET, PUT, etc.) accepts one TCP connection. Is it possible to use one TCP connection to receive several POST?

I am currently using the following:

  • Rails 3.2
  • Ruby 1.9.3 (if necessary, you can switch to 2.0)

EDIT

To help figure out what my goal is:

, 1000 (3 , 2 ). Ruby on Rails. , HTTP ( , rails). , . , , "" HTTP-API, API- .

+4
2

, Net:: HTTP:: Persistent - , . , . , API, .

: , , multipart POST . push.

- chunk-encoded. , - , . HTTP/1.1 , ( ) , , Content-Length (cf RFC 2616, 4.4). , , -, , (, nginx v1.3.9).

JSON, . RoR . , , , , . , JSON , MessagePack.

, , .

, ( ):

POST /api/endpoint HTTP/1.1
Host: example.com
Content-Type: multipart/mixed; boundary="---boundary-"
Transfer-Encoding: chunked
Content-Encoding: deflate

---boundary-
Content-Type: application/json

{...}
---boundary-
Content-Type: application/json

{...}
---boundary---

mime multipart/mixed, , . , . , , , multipart/mixed . deflate gzip , CRC32. ( ).

+5

, HTTP-, , , , HTTP . , - .

. Heroku: https://devcenter.heroku.com/articles/ruby-websockets

, . API Twitter : https://dev.twitter.com/docs/streaming-apis

, , , , .

2cents

0

All Articles