Perl API for MongoDB (MongoDB::Async) does not have a callback argument? -
i want benchmark mongodb perl async api. (mongodb::aysnc). when insert 70k times asynchronously in loop, receive 30%-40% response against queries mongodb. while mongodb inserts 5k times in second synchronously. can please guide me how can improve performance.
and functions provided mongodb::async not have callback argument, like:
#!/usr/bin/perl # # traditional first program. # strict , warnings recommended. use strict; use warnings; use benchmark; use mongodb::async; use mongodb::async::pool; use coro; use ev; use coro::ev; use coro::anyevent; $id; $pool = mongodb::async::pool->new( { host => 'localhost', port => 27017 }, { timeout => 0, max_conns => 50 } ); $it = 10; $t0 = benchmark->new; $revents; # io ( $i = 0; $i < $it; $i++ ) { async { # parallel query $id = $pool->get->mydb->users->insert( { "first_name" => "talha", "last_name" => "umair", "age" => $i } ); #for insert query uncomment line print "received ($i) $id \n"; }; } $t1 = benchmark->new; $td = timestr( timediff( $t1, $t0 ) ); print "$it iteration took $td seconds \n"; ev::loop; # stuck in loop exit it. print "control returned main function\n";
so, how can use them? can give example?
thanks in advance
the comment neil lunn said feel people seeing in future need see more obvious. question basically: "how can use callbacks in mongodb::async" , answer is:
you can't, not support them. mentioned in comment, mango support them this:
use mango::collection; $db = mango->new('mongodb://localhost:27017')->db('test'); $collection = mango::collection->new(db => $db); ( $i = 0; $i < $it; $i++ ) { $collection->insert({ "first_name" => "talha", "last_name" => "umair", "age" => $i } => sub { ($collection, $err, $oid) = @_; print "received ($i) $oid \n"; }); } mojo::ioloop->start unless mojo::ioloop->is_running;
Comments
Post a Comment