evdispatch 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/evdispatch/version.rb +1 -1
- data/website/index.html +48 -3
- data/website/index.txt +46 -3
- metadata +1 -1
data/lib/evdispatch/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -25,9 +25,7 @@
|
|
25
25
|
<h2>What</h2>
|
26
26
|
|
27
27
|
|
28
|
-
<p>A library for making
|
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’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"><</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">("</span><span class="string">http://10.0.6.45/service/blogs</span><span class="punct">")</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">("</span><span class="string">http://10.0.6.45/service/news</span><span class="punct">")</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">("</span><span class="string">http://10.0.6.45/service/messages</span><span class="punct">")</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"><%</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">%></span><span class="string">
|
67
|
+
<ul</span><span class="punct">></span>
|
68
|
+
<span class="punct"><%</span> <span class="keyword">for</span> <span class="ident">b</span> <span class="keyword">in</span> <span class="ident">blogs</span> <span class="punct">%></span><span class="string">
|
69
|
+
<li</span><span class="punct">><</span><span class="ident">a</span> <span class="ident">href</span><span class="punct">="</span><span class="string"><%= b['link'] %></span><span class="punct">"</span> <span class="punct">><%=</span><span class="string"> b['title'] %></a></li>
|
70
|
+
<% end %>
|
71
|
+
</ul>
|
72
|
+
<% 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">%></span><span class="string">
|
73
|
+
<ul</span><span class="punct">></span>
|
74
|
+
<span class="punct"><%</span> <span class="keyword">for</span> <span class="ident">n</span> <span class="keyword">in</span> <span class="ident">news</span> <span class="punct">%></span><span class="string">
|
75
|
+
<li</span><span class="punct">><</span><span class="ident">a</span> <span class="ident">href</span><span class="punct">="</span><span class="string"><%= n['link'] %></span><span class="punct">"</span> <span class="punct">><%=</span><span class="string"> n['title'] %></a></li>
|
76
|
+
<% end %>
|
77
|
+
</ul><span class="normal">
|
78
|
+
</span></span></pre></p>
|
79
|
+
|
80
|
+
|
81
|
+
<p>What’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’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
|
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">
|