website/index.html in evdispatch-0.1.2 vs website/index.html in evdispatch-0.1.3

- old
+ new

@@ -23,21 +23,66 @@ <h4 style="float:right;padding-right:10px;">&#x2192; &#8216;evdispatch&#8217;</h4> <h2>What</h2> - <p>A library for making http requests in parallel. Uses the libev library to run -an event loop on a background posix thread, that uses libcurls multi interface -to issue <span class="caps">HTTP</span> requests.</p> + <p>A library for making <span class="caps">HTTP</span> requests in parallel.</p> <h2>Installing</h2> <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">evdispatch</span></pre></p> <h2>The basics</h2> + + + <p>The library provides an interface to a background <a href="http://en.wikipedia.org/wiki/POSIX_Threads">posix thread</a> +running a <a href="http://software.schmorp.de/pkg/libev.html">libev</a> event loop. +<span class="caps">HTTP</span> requests are processed using <a href="http://curl.haxx.se/">libcurl</a> and it&#8217;s <a href="http://curl.haxx.se/libcurl/c/libcurl-multi.html">multi interface</a>. +From Ruby requests and responses are passed back and forth to the event loop +thread using a synchronized queue. In the future, responses may be processed +in ruby by monitoring a file handle, making it possible to use IO.select.</p> + + + <p>The intended use of this library was to provide a method for +web applications to make multiple concurrent to satisify a single request.</p> + + + <p>For example in rails this might look like:</p> + + + <p><pre class='syntax'> + + <span class="keyword">class </span><span class="class">DashController</span> <span class="punct">&lt;</span> <span class="constant">ApplicationController</span> + <span class="keyword">def </span><span class="method">index</span> + <span class="attribute">@blogs_id</span> <span class="punct">=</span> <span class="global">$dispatcher</span><span class="punct">.</span><span class="ident">request_http</span><span class="punct">(&quot;</span><span class="string">http://10.0.6.45/service/blogs</span><span class="punct">&quot;)</span> + <span class="attribute">@news_id</span> <span class="punct">=</span> <span class="global">$dispatcher</span><span class="punct">.</span><span class="ident">request_http</span><span class="punct">(&quot;</span><span class="string">http://10.0.6.45/service/news</span><span class="punct">&quot;)</span> + <span class="attribute">@messages_id</span> <span class="punct">=</span> <span class="global">$dispatcher</span><span class="punct">.</span><span class="ident">request_http</span><span class="punct">(&quot;</span><span class="string">http://10.0.6.45/service/messages</span><span class="punct">&quot;)</span> + <span class="keyword">end</span> + <span class="keyword">end</span> + + <span class="ident">index</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span> + <span class="punct">&lt;%</span> <span class="ident">blogs</span> <span class="punct">=</span> <span class="constant">JSON</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">(</span><span class="global">$dispatcher</span><span class="punct">.</span><span class="ident">response</span><span class="punct">(</span><span class="attribute">@blogs_id</span><span class="punct">)[</span><span class="symbol">:body</span><span class="punct">])</span> <span class="punct">%&gt;</span><span class="string"> + &lt;ul</span><span class="punct">&gt;</span> + <span class="punct">&lt;%</span> <span class="keyword">for</span> <span class="ident">b</span> <span class="keyword">in</span> <span class="ident">blogs</span> <span class="punct">%&gt;</span><span class="string"> + &lt;li</span><span class="punct">&gt;&lt;</span><span class="ident">a</span> <span class="ident">href</span><span class="punct">=&quot;</span><span class="string">&lt;%= b['link'] %&gt;</span><span class="punct">&quot;</span> <span class="punct">&gt;&lt;%=</span><span class="string"> b['title'] %&gt;&lt;/a&gt;&lt;/li&gt; + &lt;% end %&gt; + &lt;/ul&gt; + &lt;% news </span><span class="punct">=</span> <span class="constant">JSON</span><span class="punct">.</span><span class="ident">parse</span><span class="punct">(</span><span class="global">$dispatcher</span><span class="punct">.</span><span class="ident">response</span><span class="punct">(</span><span class="attribute">@news_id</span><span class="punct">)[</span><span class="symbol">:body</span><span class="punct">])</span> <span class="punct">%&gt;</span><span class="string"> + &lt;ul</span><span class="punct">&gt;</span> + <span class="punct">&lt;%</span> <span class="keyword">for</span> <span class="ident">n</span> <span class="keyword">in</span> <span class="ident">news</span> <span class="punct">%&gt;</span><span class="string"> + &lt;li</span><span class="punct">&gt;&lt;</span><span class="ident">a</span> <span class="ident">href</span><span class="punct">=&quot;</span><span class="string">&lt;%= n['link'] %&gt;</span><span class="punct">&quot;</span> <span class="punct">&gt;&lt;%=</span><span class="string"> n['title'] %&gt;&lt;/a&gt;&lt;/li&gt; + &lt;% end %&gt; + &lt;/ul&gt;<span class="normal"> +</span></span></pre></p> + + + <p>What&#8217;s interesting is if the blogs response is not back and it blocks on $dispatcher.response(@blogs_id) +chances are high that the news_id will have returned it&#8217;s response +by the time it gets finished with the blogs. This is because the background thread does not block while ruby waits for the first response. +One thing to keep in mind is the background thread will block if it has to resolve <span class="caps">DNS</span> names.</p> <h2>Demonstration of usage</h2>