<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged oplm</title>
    <link href="https://passingcuriosity.com/tags/oplm/oplm.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/oplm/oplm.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2010-01-18T00:00:00Z</updated>
    <entry>
    <title>Notes on Introducing Gearman</title>
    <link href="https://passingcuriosity.com/2010/oplm2010-2-gearman/" />
    <id>https://passingcuriosity.com/2010/oplm2010-2-gearman/</id>
    <published>2010-01-18T00:00:00Z</published>
    <updated>2010-01-18T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>The second talk at the <a href="http://blogs.tucs.org.au/oplm/">Open Programming Language Miniconf 2010</a> was
by <a href="http://datacharmer.blogspot.com">Giuseppe Maxia</a>’s <em><a href="http://blogs.tucs.org.au/oplm/programme/#gearman">Introducing Gearman – Distributed server for all
languages</a></em>. Though there were a few issues – the power dropped out,
taking the projector, audio, and recording gear out – it was an interesting
introduction to a system that I want to learn more about.</p>
<p>After a bit of background on the mainframe, mini, server, desktop progression,
Guiseppe introduced the space that Gearman operates in: distributed
heterogenous system (like the web). Amongst Gearman’s peers in the space
(not to say that they fill the same role 2at all) is <code>memcached</code>.</p>
<p>Gearman is a client/server system for distributing jobs from clients to a
number of workers. Guiseppe drew an analogy to a manager in a company: the
manager gets a request from a customer, delegates it to one or more employees,
and hands the result back to the client (monitoring progress along the way and
assigning the job to new employee/s if the current ones are, e.g., hit by a
bus).</p>
<p>The Gearman server fills the role of the manager: it accepts connections from
clients and one or more workers (which can be local to the server or on other
hosts). The Gearman server is responsible for then farming the jobs submitted
by the clients out to appropriate worker/s for execution.</p>
<p>There are a numerous ways that this can be useful. It can help to decouple
applications and features from each other. Rather than re-writing existing
components for use in projects in another language or on a different platform,
you can use Gearman to mediate the invocation of the existing code from the
new system. Similarly, you can use it to offload computationally intensive
tasks to more capable systems.</p>
<p>Using Gearman is reasonably simple: the <code>gearmand</code> server is written in C and
there are client libraries available for, according to Guiseppe, “everything
that counts”: C/C++, PHP, Python, etc. You just start a server, start one or
more workers, and then use one (or more) of the available client libraries to
submit jobs.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Start a server</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="va">PORT</span><span class="op">=</span>1234</span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="ex">gearmand</span> <span class="at">-d</span> <span class="at">-v</span> <span class="at">-p</span> <span class="va">$PORT</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="co"># Start a worker</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a><span class="ex">gearman</span> <span class="at">-p</span> <span class="va">$PORT</span> <span class="at">-f</span> count_lines <span class="at">--</span> wc <span class="at">-l</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a><span class="co"># Submit a job</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a><span class="ex">gearman</span> <span class="at">-p</span> <span class="va">$PORT</span> <span class="at">-h</span> localhost <span class="at">-f</span> count_lines <span class="op">&lt;</span> /etc/passwd</span></code></pre></div>
<p>The above code starts a Gearman server, starts a worker that can compute the
<code>count_lines</code> function (by running <code>wc -l</code> on its input), and submits a job.</p>
<p>There are some rather more complex uses. One of those that Guiseppe mentioned
is using the client in user defined functions in a relational database server
(he used <a href="http://forge.mysql.com/tools/tool.php?id=235">MySQL</a>, but PostgreSQL is also supported). With appropriate
jobs and workers this can be used to retrieve status information from, e.g.,
MySQL slave servers and store it in a database on the master (which will then
be replicated to the slaves giving all nodes knowledge of the health of the
whole cluster).</p>
<p>To help avoid introducing a single point of failure, you can deploy multiple
servers and use all of them: if one fails, then clients and workers will try
the next. It wasn’t clear, though, if the client libraries do this sensibly
(re-submitting jobs, etc.)</p>
<p>For more information, your first stop should probably be the official
<a href="http://gearman.org/">Gearman</a> web-site. There are also a number of posts on <a href="http://datacharmer.blogspot.com">Guiseppe’s
blog</a>.</p>]]></summary>
</entry>

</feed>
