search

Home  >  Q&A  >  body text

mongodb的线程池设置不起作用

最近遇到线程池的问题,默认mongodb为每个连接(即new 出的一个连接对象)分配了一个线程池,里面最多有10个线程,网上说可以通过MongoOpection的connectionPerHost参数来调整线程池的大小,但是实际上无论我怎么修改这个参数的值线程池的大小都是10,请问这个是为什么,是不是有什么地方也要修改?

另外,对于一个网页的应用,是客户端每次点击界面产生一个连接(new一个连接的对象)的设计好,还是在程序开始的时候new一个连接,然后分配给它较大的线程池,每次客户连接就从线程池里面取一个的方式好? 个人感觉第一种在高并发的情况下对系统的负载较高。

迷茫迷茫2765 days ago616

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-24 09:14:41

    I found the reason myself:
    1 The default number of threads is 10 because the JAVA driver version used is too old. The version is 2.2, and the latest version is 2.12. The default thread pool for one connection has been set to 100
    2 The suggestion given in the official documentation is to open a connection and then take the connection from the thread pool
    3 In the 2.12 version, the MongoOperation class was abolished, but it can be used. Although setting the connectionPerHost parameter can ostensibly modify the number of threads in the thread pool in the connection parameters, in fact the upper limit of the thread pool in the system background is still 100, and there is no parameter. It takes effect (I wonder if there is another setting method), but I personally think it is not too important. If the thread pool can consistently occupy more than 100, there is probably something wrong with the system design

    reply
    0
  • Cancelreply