# Twisted for Ruby?

**URL:** <https://rubytalk.org/t/twisted-for-ruby/27280>\
**Category:** ruby-talk\
**Created:** [9 May 2006 12:34 UTC](https://rubytalk.org/t/twisted-for-ruby/27280 "2006-05-09T12:34:24Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [9 May 2006 12:34 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/1 "2006-05-09T12:34:24Z")

</div>

All:  
On another thread ("Considering Ruby for a Network Application), Giles  
Bowkett made reference to the "Twisted" application framework available to  
Python programmers, and that got me thinking. How many of you are familiar  
with Twisted or have used it to develop an application? I'd like to know if  
there is any interest among Rubyists in having such a well-elaborated  
event-handling framework for Ruby.

I recently released a single-threaded reactor-based library called  
"EventMachine," which could form the basis for a more complete framework.  
This codebase is the result of a lot of experience with high-performance  
network servers, and it supports TCP, UDP, SSL/TLS and timer events now. To  
bring it up to the next level, we'd need to add support for other kinds of  
events, like keyboard, disk i/o, IPC, and programmatically-generated  
pseudo-events. We'd probably also want a thread-pool manager. It might also  
be fun to layer Drb on top of EventMachine.

For protocol support, Twisted uses a plugin model. EventMachine uses a more  
Ruby-esque mixin model, and we have already used it to build an HTTP/S  
server ("monorail," released on Rubyforge), an LDAP server ("Peregrine," not  
yet publicly released), a SIP proxy and an SMTP server (not released  
publicly yet). Other things like RADIUS, SOAP/REST, instant messaging are  
also possible.

Comments? Complaints? Wish-lists? Anyone wanna help?

---

<div class="post-metadata">

**Author:** ![Daniel\_Harple](https://avatars.discourse-cdn.com/v4/letter/d/5daacb/32.png) [@Daniel\_Harple](https://rubytalk.org/u/Daniel_Harple)\
**Post date:** [9 May 2006 12:54 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/2 "2006-05-09T12:54:30Z")

</div>

I think you will find a lot of interest, but IMO it would be best for the lib to be wrote in Ruby instead of C++.

This recent interest in event-driven networking is an odd coincidence, since I am currently writing a networking app, and I was going to roll my own base for it. I looked at using EventMachine, but I have decided not to because it requires a C++ compiler.

-- Daniel

> **···**
>
> On May 9, 2006, at 2:34 PM, Francis Cianfrocca wrote:
> 
> > On another thread ("Considering Ruby for a Network Application), Giles  
> > Bowkett made reference to the "Twisted" application framework available to  
> > Python programmers, and that got me thinking. How many of you are familiar  
> > with Twisted or have used it to develop an application? I'd like to know if  
> > there is any interest among Rubyists in having such a well-elaborated  
> > event-handling framework for Ruby.
> > 
> > I recently released a single-threaded reactor-based library called  
> > "EventMachine," which could form the basis for a more complete framework.  
> > [...]  
> > Comments? Complaints? Wish-lists? Anyone wanna help?

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [9 May 2006 12:57 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/3 "2006-05-09T12:57:41Z")

</div>

My opinion is that this would make you a lot of new friends. 😉

James Edward Gray II

> **···**
>
> On May 9, 2006, at 7:34 AM, Francis Cianfrocca wrote:
> 
> > I'd like to know if there is any interest among Rubyists in having such a well-elaborated  
> > event-handling framework for Ruby.

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [9 May 2006 13:18 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/4 "2006-05-09T13:18:43Z")

</div>

I appreciate your comment. We did EventMachine in C++ for some particular  
reasons: Performance and scalability of course, but also we learned (the  
hard way) that Ruby's implementations of network i/o are not as well-behaved  
as we'd hoped. (So what does that borderline-provocative statement actually  
mean :-)? I think that Ruby attempts to be very good about wrapping up the  
details, so it handles normal cases very well, but there are some subtle  
edge conditions that come up in production network applications that Ruby  
doesn't expose. And they cause trouble. I'm used to writing single-process,  
single-thread network servers that can handle thousands of users, and run  
for months or years without restarting or throwing exceptions.)

All that said, I recognize the pain-in-the-neck resulting from having to  
compile the extension. Does it make you any more comfortable if we release  
binary versions for all the various platforms? Another thing we could do  
easily enough is backport the code from C++ to C. Would that help? And  
finally, are you writing for Windows, Mac or Solaris (where compilers are  
generally not available) or Linux or BSD (where they often are)?

> **···**
>
> On 5/9/06, Daniel Harple \<dharple@generalconsumption.org\> wrote:
> 
> > On May 9, 2006, at 2:34 PM, Francis Cianfrocca wrote:
> > 
> > \> On another thread ("Considering Ruby for a Network Application), Giles  
> > \> Bowkett made reference to the "Twisted" application framework  
> > \> available to  
> > \> Python programmers, and that got me thinking. How many of you are  
> > \> familiar  
> > \> with Twisted or have used it to develop an application? I'd like to  
> > \> know if  
> > \> there is any interest among Rubyists in having such a well-elaborated  
> > \> event-handling framework for Ruby.  
> > \>  
> > \> I recently released a single-threaded reactor-based library called  
> > \> "EventMachine," which could form the basis for a more complete  
> > \> framework.  
> > \> [...]  
> > \> Comments? Complaints? Wish-lists? Anyone wanna help?
> > 
> > I think you will find a lot of interest, but IMO it would be best for  
> > the lib to be wrote in Ruby instead of C++.
> > 
> > This recent interest in event-driven networking is an odd  
> > coincidence, since I am currently writing a networking app, and I was  
> > going to roll my own base for it. I looked at using EventMachine, but  
> > I have decided not to because it requires a C++ compiler.
> > 
> > -- Daniel

---

<div class="post-metadata">

**Author:** ![James\_Edward\_Gray\_II](https://avatars.discourse-cdn.com/v4/letter/j/ea5d25/32.png) [@James\_Edward\_Gray\_II](https://rubytalk.org/u/James_Edward_Gray_II)\
**Post date:** [9 May 2006 13:29 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/5 "2006-05-09T13:29:07Z")

</div>

Just a minor correction here: Mac OS X is a Unix flavor so compilers are very available for it. I doubt Ruby ran on earlier versions of the Mac OS where that was not true.

James Edward Gray II

> **···**
>
> On May 9, 2006, at 8:18 AM, Francis Cianfrocca wrote:
> 
> > And finally, are you writing for Windows, Mac or Solaris (where compilers are  
> > generally not available)...

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [9 May 2006 13:40 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/6 "2006-05-09T13:40:33Z")

</div>

Understood, but I was thinking about the masses of OSX machines out  
there not running on programmer's desks, so they haven't installed the  
dev package. The same is true for Solaris (most definitely a Unix  
flavor!), since most of those machines have nothing but the cruddy  
little /usr/ccs/cc compiler or nothing at all. I asked the question  
because I'm wondering if Daniel Harple is thinking about the issues he  
may face with distributing his new application widely, or if he's just  
uncomfortable with extensions per se.

> **···**
>
> On 5/9/06, James Edward Gray II \<james@grayproductions.net\> wrote:
> 
> > On May 9, 2006, at 8:18 AM, Francis Cianfrocca wrote:
> > 
> > \> And finally, are you writing for Windows, Mac or Solaris (where  
> > \> compilers are  
> > \> generally not available)...
> > 
> > Just a minor correction here: Mac OS X is a Unix flavor so compilers  
> > are very available for it. I doubt Ruby ran on earlier versions of  
> > the Mac OS where that was not true.
> > 
> > James Edward Gray II

---

<div class="post-metadata">

**Author:** ![William\_Groppe](https://avatars.discourse-cdn.com/v4/letter/w/e47c2d/32.png) [@William\_Groppe](https://rubytalk.org/u/William_Groppe)\
**Post date:** [9 May 2006 14:35 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/7 "2006-05-09T14:35:28Z")

</div>

C++ or not, I think this would be an excellent addition to the  
ruby-verse. I have at least two projects that could use this kind of  
framework. I'd be happy to test the ruby/os x side of things.

-Will

---

<div class="post-metadata">

**Author:** ![Benjohn\_Barnes](https://avatars.discourse-cdn.com/v4/letter/b/df705f/32.png) [@Benjohn\_Barnes](https://rubytalk.org/u/Benjohn_Barnes)\
**Post date:** [9 May 2006 15:15 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/8 "2006-05-09T15:15:27Z")

</div>

> C++ or not, I think this would be an excellent addition to the  
> ruby-verse. I have at least two projects that could use this kind of  
> framework. I'd be happy to test the ruby/os x side of things.

Would it be terrifically difficult to have both a c++ implementation,  
and a pure Ruby one? 🙂 You'd guess the Ruby implementation would be  
about a 10th the size anyway 😉

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [9 May 2006 15:23 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/9 "2006-05-09T15:23:53Z")

</div>

LOL! Considering we're doing essentially a completely parallel rewrite of  
EventMachine for Windows (using I/O completion ports), and will probably do  
one for Linux 2.6 kernels (using epoll), it wouldn't take much to do one in  
pure Ruby, but it might be light on features. Certainly would be light on  
performance.

> **···**
>
> On 5/9/06, benjohn@fysh.org \<benjohn@fysh.org\> wrote:
> 
> > \> C++ or not, I think this would be an excellent addition to the  
> > \> ruby-verse. I have at least two projects that could use this kind of  
> > \> framework. I'd be happy to test the ruby/os x side of things.
> > 
> > Would it be terrifically difficult to have both a c++ implementation,  
> > and a pure Ruby one? 🙂 You'd guess the Ruby implementation would be  
> > about a 10th the size anyway 😉

---

<div class="post-metadata">

**Author:** ![Tsuraan1](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@Tsuraan1](https://rubytalk.org/u/Tsuraan1)\
**Post date:** [9 May 2006 17:39 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/10 "2006-05-09T17:39:30Z")

</div>

> LOL! Considering we're doing essentially a completely parallel rewrite of  
> EventMachine for Windows (using I/O completion ports), and will probably do  
> one for Linux 2.6 kernels (using epoll), it wouldn't take much to do one in

Is libevent an option for this? I don't really know much about it, but it seems to wrap poll/epoll type things pretty nicely.

---

<div class="post-metadata">

**Author:** ![Francis\_Cianfrocca](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@Francis\_Cianfrocca](https://rubytalk.org/u/Francis_Cianfrocca)\
**Post date:** [9 May 2006 18:05 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/11 "2006-05-09T18:05:07Z")

</div>

I believe this has been tried and didn't work all that well. Among  
other things, there were issues interacting with Ruby threads. With  
EventMachine, we set out from the beginning to do something that would  
be Ruby-esque.

> **···**
>
> On 5/9/06, tsuraan@tsuraan.net \<tsuraan@tsuraan.net\> wrote:
> 
> > \> LOL! Considering we're doing essentially a completely parallel rewrite  
> > \> of  
> > \> EventMachine for Windows (using I/O completion ports), and will  
> > \> probably do  
> > \> one for Linux 2.6 kernels (using epoll), it wouldn't take much to do  
> > \> one in
> > 
> > Is libevent an option for this? I don't really know much about it, but  
> > it seems to wrap poll/epoll type things pretty nicely.

---

<div class="post-metadata">

**Author:** ![Zed\_A\_Shaw](https://avatars.discourse-cdn.com/v4/letter/z/5fc32e/32.png) [@Zed\_A\_Shaw](https://rubytalk.org/u/Zed_A_Shaw)\
**Post date:** [12 May 2006 07:07 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/12 "2006-05-12T07:07:22Z")

</div>

Already did that a long time ago.  
[http://www.zedshaw.com/projects/ruby\_event/](http://www.zedshaw.com/projects/ruby_event/) and it worked OK. Even  
implemented the original SCGI Rails Runner using it as well as a telnet  
processor. Problem came from a clash with select in Ruby and libevent.

Francis solved it by using a pthread to run the select separately from  
the ruby interpreter. Something similar could be done with Ruby/Event  
but most of my time is spent on Mongrel these days.

Incidentally, Ruby is apparently picking up libevent based events rather  
than select for it's threads so a lot of this might be totally useless  
in a year, or two, or ten, or whenever.

> **···**
>
> On Wed, 2006-05-10 at 02:39 +0900, tsuraan@tsuraan.net wrote:
> 
> > \> LOL! Considering we're doing essentially a completely parallel rewrite  
> > \> of  
> > \> EventMachine for Windows (using I/O completion ports), and will  
> > \> probably do  
> > \> one for Linux 2.6 kernels (using epoll), it wouldn't take much to do  
> > \> one in
> > 
> > Is libevent an option for this? I don't really know much about it, but  
> > it seems to wrap poll/epoll type things pretty nicely.
> 
> --  
> Zed A. Shaw
> 
> > **[Zed A. shaw](https://zedshaw.com/)**
> >
> > Personal essays and writings by Zed A. Shaw.
> 
> [http://mongrel.rubyforge.org/](http://mongrel.rubyforge.org/)

---

<div class="post-metadata">

**Author:** ![Gyoung-Yoon\_Noh1](https://avatars.discourse-cdn.com/v4/letter/g/dbc845/32.png) [@Gyoung-Yoon\_Noh1](https://rubytalk.org/u/Gyoung-Yoon_Noh1)\
**Post date:** [12 May 2006 07:29 UTC](https://rubytalk.org/t/twisted-for-ruby/27280/13 "2006-05-12T07:29:41Z")

</div>

Is it true? If so, that means future ruby implementation would  
have dependency with libevent?

> **···**
>
> On 5/12/06, Zed Shaw \<zedshaw@zedshaw.com\> wrote:
> 
> > Incidentally, Ruby is apparently picking up libevent based events rather  
> > than select for it's threads so a lot of this might be totally useless  
> > in a year, or two, or ten, or whenever.
> 
> --  
> [http://nohmad.sub-port.net](http://nohmad.sub-port.net)
