<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sin ambición &#187; Desarollo</title>
	<atom:link href="http://www.guero.net/page/desarollo/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.guero.net</link>
	<description>Detalles técnicos del mundo del desarrollo web y sistemas, proyectos y opinión.</description>
	<lastBuildDate>Fri, 19 Aug 2011 16:49:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Threads en Perl</title>
		<link>http://www.guero.net/2010/04/threads-en-perl/</link>
		<comments>http://www.guero.net/2010/04/threads-en-perl/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 10:05:27 +0000</pubDate>
		<dc:creator>Gabriel</dc:creator>
				<category><![CDATA[Desarollo]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[perl threads]]></category>

		<guid isPermaLink="false">http://www.guero.net/?p=204</guid>
		<description><![CDATA[Threads es una función que tiene muchos años pero no lo había implementado nunca. Ahora que estoy desarrollando un demonio en Perl utilizando POE y es muy útil y sobre todo fácil de implementar, un ejemplo: #!/usr/bin/perl use threads; use threads::shared; use LWP::UserAgent; use Data::Dumper; my $params = &#123; url =&#62; 'http://www.guero.net' &#125;; my $_R [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://perldoc.perl.org/threads.html">Threads</a> es una función que tiene muchos años pero no lo había implementado nunca. Ahora que estoy desarrollando un demonio en Perl utilizando <a href="http://poe.perl.org/">POE</a> y es muy útil y sobre todo fácil de implementar, un ejemplo:</p>
<div class="codecolorer-container perl vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="perl codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span><br />
<br />
<span style="color: #000000; font-weight: bold;">use</span> threads<span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> threads<span style="color: #339933;">::</span><span style="color: #006600;">shared</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> LWP<span style="color: #339933;">::</span><span style="color: #006600;">UserAgent</span><span style="color: #339933;">;</span><br />
<span style="color: #000000; font-weight: bold;">use</span> Data<span style="color: #339933;">::</span><span style="color: #006600;">Dumper</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$params</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#123;</span> url <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'http://www.guero.net'</span> <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$_R</span> <span style="color: #339933;">=</span> threads<span style="color: #339933;">-&gt;</span><span style="color: #006600;">create</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">sub</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ua</span> <span style="color: #339933;">=</span> LWP<span style="color: #339933;">::</span><span style="color: #006600;">UserAgent</span><span style="color: #339933;">-&gt;</span><span style="color: #000000; font-weight: bold;">new</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$response</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$ua</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">get</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">$params</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>url<span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">is_success</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">return</span> <span style="color: #0000ff;">$response</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">decoded_content</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$params</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #000066;">print</span> Dumper<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$_R</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Hay muchas formas de utilizarlo, como siempre el Perl para todo hay mil maneras. El ejemplo este no tiene mucho sentido ya que para un simple get no hace falta mayor cosa pero si se tuviera que hacer algo que consuma mucho CPU es muy útil.</p>
<p>En el caso que estoy ahora (un servidor TCP) tenía el problema que al ejecutar tareas que requieren mucho CPU el servidor deja de responder mientras realiza la tarea ya que solo utiliza una CPU y va al 100%. Lanzando estas tareas con &#8220;<a href="http://es.wikipedia.org/wiki/Threads">threads</a>&#8221; el servidor sigue respondiendo con normalidad mientras otro hilo está realizando la costosa tarea.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.guero.net/2010/04/threads-en-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

