evdispatch 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module Evdispatch #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/website/index.html CHANGED
@@ -25,9 +25,7 @@
25
25
  <h2>What</h2>
26
26
 
27
27
 
28
- <p>A library for making http requests in parallel. Uses the libev library to run
29
- an event loop on a background posix thread, that uses libcurls multi interface
30
- to issue <span class="caps">HTTP</span> requests.</p>
28
+ <p>A library for making <span class="caps">HTTP</span> requests in parallel.</p>
31
29
 
32
30
 
33
31
  <h2>Installing</h2>
@@ -39,6 +37,53 @@ to issue <span class="caps">HTTP</span> requests.</p>
39
37
  <h2>The basics</h2>
40
38
 
41
39
 
40
+ <p>The library provides an interface to a background <a href="http://en.wikipedia.org/wiki/POSIX_Threads">posix thread</a>
41
+ running a <a href="http://software.schmorp.de/pkg/libev.html">libev</a> event loop.
42
+ <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>.
43
+ From Ruby requests and responses are passed back and forth to the event loop
44
+ thread using a synchronized queue. In the future, responses may be processed
45
+ in ruby by monitoring a file handle, making it possible to use IO.select.</p>
46
+
47
+
48
+ <p>The intended use of this library was to provide a method for
49
+ web applications to make multiple concurrent to satisify a single request.</p>
50
+
51
+
52
+ <p>For example in rails this might look like:</p>
53
+
54
+
55
+ <p><pre class='syntax'>
56
+
57
+ <span class="keyword">class </span><span class="class">DashController</span> <span class="punct">&lt;</span> <span class="constant">ApplicationController</span>
58
+ <span class="keyword">def </span><span class="method">index</span>
59
+ <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>
60
+ <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>
61
+ <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>
62
+ <span class="keyword">end</span>
63
+ <span class="keyword">end</span>
64
+
65
+ <span class="ident">index</span><span class="punct">.</span><span class="ident">html</span><span class="punct">.</span><span class="ident">erb</span>
66
+ <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">
67
+ &lt;ul</span><span class="punct">&gt;</span>
68
+ <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">
69
+ &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;
70
+ &lt;% end %&gt;
71
+ &lt;/ul&gt;
72
+ &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">
73
+ &lt;ul</span><span class="punct">&gt;</span>
74
+ <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">
75
+ &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;
76
+ &lt;% end %&gt;
77
+ &lt;/ul&gt;<span class="normal">
78
+ </span></span></pre></p>
79
+
80
+
81
+ <p>What&#8217;s interesting is if the blogs response is not back and it blocks on $dispatcher.response(@blogs_id)
82
+ chances are high that the news_id will have returned it&#8217;s response
83
+ 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.
84
+ One thing to keep in mind is the background thread will block if it has to resolve <span class="caps">DNS</span> names.</p>
85
+
86
+
42
87
  <h2>Demonstration of usage</h2>
43
88
 
44
89
 
data/website/index.txt CHANGED
@@ -5,9 +5,7 @@ h1. evdispatch
5
5
 
6
6
  h2. What
7
7
 
8
- A library for making http requests in parallel. Uses the libev library to run
9
- an event loop on a background posix thread, that uses libcurls multi interface
10
- to issue HTTP requests.
8
+ A library for making HTTP requests in parallel.
11
9
 
12
10
  h2. Installing
13
11
 
@@ -16,6 +14,51 @@ h2. Installing
16
14
  h2. The basics
17
15
 
18
16
 
17
+ The library provides an interface to a background <a href="http://en.wikipedia.org/wiki/POSIX_Threads">posix thread</a>
18
+ running a <a href="http://software.schmorp.de/pkg/libev.html">libev</a> event loop.
19
+ HTTP requests are processed using <a href="http://curl.haxx.se/">libcurl</a> and it's <a href="http://curl.haxx.se/libcurl/c/libcurl-multi.html">multi interface</a>.
20
+ From Ruby requests and responses are passed back and forth to the event loop
21
+ thread using a synchronized queue. In the future, responses may be processed
22
+ in ruby by monitoring a file handle, making it possible to use IO.select.
23
+
24
+
25
+ The intended use of this library was to provide a method for
26
+ web applications to make multiple concurrent to satisify a single request.
27
+
28
+
29
+ For example in rails this might look like:
30
+
31
+ <pre syntax="ruby">
32
+
33
+ class DashController < ApplicationController
34
+ def index
35
+ @blogs_id = $dispatcher.request_http("http://10.0.6.45/service/blogs")
36
+ @news_id = $dispatcher.request_http("http://10.0.6.45/service/news")
37
+ @messages_id = $dispatcher.request_http("http://10.0.6.45/service/messages")
38
+ end
39
+ end
40
+
41
+ index.html.erb
42
+ <% blogs = JSON.parse($dispatcher.response(@blogs_id)[:body]) %>
43
+ <ul>
44
+ <% for b in blogs %>
45
+ <li><a href="<%= b['link'] %>" ><%= b['title'] %></a></li>
46
+ <% end %>
47
+ </ul>
48
+ <% news = JSON.parse($dispatcher.response(@news_id)[:body]) %>
49
+ <ul>
50
+ <% for n in news %>
51
+ <li><a href="<%= n['link'] %>" ><%= n['title'] %></a></li>
52
+ <% end %>
53
+ </ul>
54
+ </pre>
55
+
56
+
57
+ What's interesting is if the blogs response is not back and it blocks on $dispatcher.response(@blogs_id)
58
+ chances are high that the news_id will have returned it's response
59
+ 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.
60
+ One thing to keep in mind is the background thread will block if it has to resolve DNS names.
61
+
19
62
  h2. Demonstration of usage
20
63
 
21
64
  <pre syntax="ruby">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evdispatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd A. Fisher