English 中文(简体)
PHP16000Mongo DB的开端和关闭
原标题:Opening and closing 16000 Mongo DB instances in PHP

目前,我正在研究一些个人测试和基准,以比较利用MongoDB和MySQL与真正的世界实例数据的工作流程和效率。

为了将我的数据输入每个数据库,我正在做数千个 lo,随机制作数据标,以插入数据库。

However I am having some issues using the Mongo class in PHP which I cannot solve. The problem is like so:

I have a loop which creates a new Mongo instance and connection, inserts a small array into a collection and then closes the connection. This loop should run 20000 times. However it is always failing around the 16300nd loop (with a min of 16200 and max of 16350 I d say after a few runs) when it attempts to create the instance/make a connection.

The Code in the loop:

$data = get_random_user_data();

$mongo = new Mongo( mongodb://admin:password@localhost:27017/test );

    if ($mongo->test->users->insert($data)) {
        $users[] = array( id  => $data[ _id ],  name  => $data[ username ]);
    echo $i." - Added user: ".$data[ username ]. <br/> ;
    }

$mongo->close();

用户——数据(数据)只是一个简单的关联阵列。

我发现的错误是:

Fatal error: Uncaught exception  MongoConnectionException  with message  Unknown error 

关于:

$mongo = new Mongo( mongodb://admin:password@localhost:27017/test );

任何想法? 是否有像一些安全或预防垃圾邮件那样根本的我失踪?

提前感谢。

www.un.org/Depts/DGACM/index_spanish.htm Extra info:

该书在114.97秒钟左右死亡。 它不是PHP的记忆或时间问题,因为所有限制都在提高,而且我昨天拥有我的MySQL基准,在大约一小时之内插入120000个浏览器(采用同样的开放连接方法,插入、密切联系),没有任何问题。

Running PHP Version 5.3.5

phpinfo Mongo info:

MongoDB Support enabled
Version 1.2.0-
Directive   Local Value Master Value
mongo.allow_empty_keys  0   0
mongo.allow_persistent  1   1
mongo.auto_reconnect    1   1
mongo.chunk_size    262144  262144
mongo.cmd   $   $
mongo.default_host  localhost   localhost
mongo.default_port  27017   27017
mongo.long_as_object    0   0
mongo.native_long   0   0
mongo.no_id 0   0
mongo.utf8  1   1
最佳回答

你的运行系统愿意开放的数量有限。 当你开张,然后关闭时,本组织立即将它放在“可用”池内,在“时间等待”状态中,它把纳塔提到

You can increase the number of sockets your OS will open, see http://www.mongodb.org/display/DOCS/Too+Many+Open+Files (each socket is an open "file").

另外,你再使用相当老的驾驶员,或许想考虑升级。

问题回答

我确认,这同样是风 rub司机的行为。 我重复了与瓦隆戈的类似情况,通过每次开张/披露邦戈的记录插入20000个记录。 而且,它仍在14110至14200年之间。

这是错误的信息。

 uncaught throw #<Mongo::ConnectionFailure: Failed to connect to host localhost and port 27017: Cannot assign requested address - connect(2)>

这是完整的追踪。

Failed to connect to host localhost and port 27017: Cannot assign requested address - connect(2)
["/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:171:in `rescue in checkout_new_socket ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:166:in `checkout_new_socket ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:267:in `block (2 levels) in checkout ", "<internal:prelude>:10:in `synchronize ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:259:in `block in checkout ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:252:in `loop ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/pool.rb:252:in `checkout ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/connection.rb:496:in `checkout_writer ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/networking.rb:34:in `send_message ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/collection.rb:948:in `block in insert_documents ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/util/logging.rb:28:in `instrument ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/collection.rb:944:in `insert_documents ", "/home/ramesh/.rvm/gems/ruby-1.9.2-p290/gems/mongo-1.5.2/lib/mongo/collection.rb:343:in `insert ", "/home/ramesh/Desktop/load_test.rb:15:in `block in load_test ", "/home/ramesh/Desktop/load_test.rb:6:in `times ", "/home/ramesh/Desktop/load_test.rb:6:in `load_test ", "(irb):2:in `irb_binding ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/workspace.rb:80:in `eval ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/workspace.rb:80:in `evaluate ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/context.rb:254:in `evaluate ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:159:in `block (2 levels) in eval_input ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:273:in `signal_status ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:156:in `block in eval_input ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:243:in `block (2 levels) in each_top_level_statement ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:155:in `eval_input ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:70:in `block in start ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `catch ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `start ", "/home/ramesh/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main> "]
ArgumentError: uncaught throw #<Mongo::ConnectionFailure: Failed to connect to host localhost and port 27017: Cannot assign requested address - connect(2)>
    from /home/ramesh/Desktop/load_test.rb:21:in `throw 
    from /home/ramesh/Desktop/load_test.rb:21:in `rescue in block in load_test 
    from /home/ramesh/Desktop/load_test.rb:7:in `block in load_test 
    from /home/ramesh/Desktop/load_test.rb:6:in `times 
    from /home/ramesh/Desktop/load_test.rb:6:in `load_test 

正如“Chrisui”所说,我也没有经历过任何记忆的下降。

这是被审判的文字。

require  mongo 

def load_test
    start = Time.now
    puts  starting at :  + start.to_s 
    20000.times do |i|    
            begin
                puts i      
            doc = {"name" => "MongoDB", "type" => "database", "count" => 1,"info" => {"x" => 203, "y" =>  102 }}
            con = Mongo::Connection.new("localhost")
            db   = con[ bulktest ]
            coll = db[ test ]
            coll.insert(doc)
            con.close
                con,db,coll=nil,nil,nil
        rescue Exception => e  
            puts e.message  
            puts e.backtrace.inspect  
            throw e 
        end

    end
    stop = Time.now
    puts  stoping at :  + stop.to_s 
    puts  elapsed time is   + (stop-start).to_s +   seconds 
end

你的基准没有意义。 开放/连接。 你们应该重复使用,而不是每次开放/披露。 如果你迅速开张,你将拥有太多时间的空缺,仍然使用档案记录员。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签