AnyMongo – MongoDB driver for AnyEvent application

最近做了一个mongoDB在AnyEvent上驱动原型,大部分代码来自官方的perl driver,部分则来自ruby driver。我觉得ruby driver
比较有意思。 替换了普通版本的sock相关的操作,使用AE的handler替代,增加了BSON的decode和encode,重写了write_***函数。
同时,提供了一个AnyMongo::Compat兼容包, 原先使用MongoDB驱动的代码应该可以直接运行,因为这个包可以通过官方0.36的
大部分测试 t/perl-driver-api/*t . 对于使用了一些底层函数比如write/recv的代码则无法兼容。

由于是prototype,所以目前版本谨供学习和参考,不可能在正式使用,因为还缺少很多功能,包括authentication, paris/replica-set
支持,reconnect, timeout 等等。

性能上也不好不坏, 对于crud操作,要比官方的快20-30%, 但对于cursor操作,则相反要慢30%1%左右。官方版本的cursor的性能也



AnyMongo使用Perl license,源码:

简单做了profiling,发现瓶颈在于一些调试代码和moose。去除调试代码,启用moose inlined destruction,

5 thoughts on “AnyMongo – MongoDB driver for AnyEvent application

  1. AnyMongo is following a more synchronous API on top of AnyEvent, it design to work with Coro,
    difference with traditional AnyEvent approach, it not provide full callback interface.
    BTW, I also make a AnyEvent:MongoDB alias, but this morning, somebody told me that he’ll release
    another AnyEvent client for mongo which will full callback approach. So, I removed this namespace for him.

  2. hi, thanks for AnyMongo !

    just a quick question, due you ended up cloning/branching a lot of MongoDB code in your object-hierarchy (well done :) – any chance to remove Any::Moose / Mouse / Moose dependency and just stick to simpler old perlobj OO style interface? :)

    basically I am looking into having a super lightweight layer on top of mongoDB XS/C code which does not require layers and layers of perl to load etc…


  3. Well, I think AnyMoose / Mouse should be native “modern” Perl object system ;-)
    We use MongoDB in our most projects, some are large, and I tied to
    fight with old Perl OO style, we need power of Moose until Perl6?
    I really suggest you should recognize that Mouse/Moose will be the standard object system of
    moden Perl5.

    Anyway, I agree, as a driver , it should be very thin and lightweight, so, if have enough
    free time, I’ll try to make a lightweight branch remove dependencies of Moose ,
    but I’m not sure it’s benefit now.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>