HTTPError is an exception that happens when a bang request ( request! / get! / …) fails. Response.headers is a struct ( HTTPotion.Headers) that wraps a map to provide case-insensitive access (so you can use response.headers and it doesn't matter if the server returned AuThOrIZatIOn or something). The Response is a struct, you can access its fields like: response.body. get! " ** ( HTTPotion.HTTPError ) econnrefused get "" % HTTPotion.Response # You can also raise `HTTPError` with the `bang` version of request iex > HTTPotion. That’s it for today, folks.Iex > response = HTTPotion. According to its documentation, gun has been designed with streaming in mind, so you might like to give it a try. HTTP streaming using ibrowse worked so well for us, that we haven’t even had a chance to try gun. You can find all the possible options in the ibrowse wiki. There is also a spawn_worker_process/1 function, so it’s possible to create a separate worker for streaming per domain. For example there is stream_chunk_size parameter that lets you set your desired chunk size. Moreover, ibrowse gives you more control on how you want to process and stream chunks. Look at the “Traffic” graph: the “in” and “out” lines are so close you can’t even see the green “out” line. Even when the gateway streams ~26 megabytes per second, memory usage stays stable around ~250 MB. The original author has since continued development of IBrowse. In cases when hackney started to consume a lot of RAM, ibrowse managed to keep memory consumption under control. IBrowse is a MUI-based web browser for the Amiga range of computers, and was a rewritten follow-on to Amiga Mosaic, one of the first web browsers for the Amiga Computer.2 IBrowse was originally developed for a company called Omnipresence, now defunct. We found that streaming with ibrowse worked very well. That’s why you have to pattern match against raw ibrowse messages. Instead, you have to pass it via the ibrowse option, but then all the messages coming from the ibrowse process are not converted to the corresponding HTTPotion structures. hackney provides an async option to receive a response asynchronously, but more importantly it allows us to pass ] option directly. Streaming with hackneyĭue to past decisions at Adjust, our application already had HTTPoison in its dependencies list, which meant we already had hackney installed in our app, so we decided to try and implement HTTP streaming based on it. With the streaming approach, there should be no significant gaps between the “in” and “out” lines on this graph, because the API gateway should send a chunk to the client as soon as that chunk is received from the requested service. Code examples in curl, Elixir, Java, PHP. In the above screenshot, the “Traffic” graph perfectly illustrates what happens without streaming: an application receives data from a requested service for quite a while (yellow line, “in”), and once all the data is there, it sends it to a client (“out” line). Learn how to send an SMS with the 46elks API and start adding SMS features to your programmable applications. In this blogpost, I’d like to describe how we’ve implemented transparent streaming of HTTP requests directly to a client. elixir-tesla/tesla GitHub elixir-tesla / tesla Public master tesla/lib/tesla/adapter/ibrowse.ex Go to file Cannot retrieve contributors at this time 99 lines (80 sloc) 2.63 KB Raw Blame if Code. Below, you can see what happened to our naïve implementation when a number of clients were trying to download sizeable reports. Because of this, downloading such a report via API gateway just to send it to a client does not sound like a good idea. These reports are usually big json or csv blobs and sometimes they are as big as a few hundred megabytes. In our case, the API gateway also stands before a service that is responsible for generating reports. As you probably know, if you’re building microservices, this approach is quite common. One of the Elixir web apps we have at Adjust acts as an API gateway - it receives a request, applies authorization and/or authentication and then passes the request along to an actual requested service.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |