Two small lessons about resource pooling

Source: Internet
Author: User
Tags connection pooling

"Do not use a global resource pool. Unless you really know it's reasonable to configure--such as size, timeout, etc. ”


I've stepped on this hole twice.

The first time is the connection pool for HTTP. I used a default Poolinghttpclientconnectionmanager to make a rest service call. Unexpectedly, in the default configuration of the HTTP connection pool, the same domain name creates up to two links. As a result, a little bit of pressure came to a tragic moment.


The second time is the thread pool. Spring's Task:annotation-driven configuration will place the global @async annotation class/method and the scheduled task in the same thread/task pool for asynchronous invocation. As a result, a large number of multithreaded operations in the system timed out when some of these tasks blocked the worker thread.


Apart from the two pits, I succeeded in avoiding a pit.

When running multi-threaded tasks using Java 8 's parallel stream, by default all threads are dispatched and run by Forkjoinpool.commonpool (). Similar to what I did when I stepped on the second pit: if there are certain tasks blocking the worker thread, other multi-threaded tasks will pay extra waiting time or even timeout.


This time I used a custom forkjoinpool to escape the pit. And I remind myself that when you use a global resource pool, you must be cautious. For example, the global thread pool, http/db connection pool, cache pool, and so on. Because the coverage and impact of the "global" are too broad, the unintentional loss of one place can lead to hundreds of problems. Such risks are too big and too uncontrolled.


However, database connection pooling is considered a special case. In fact, the database connection pool also has these risks, but in most cases, our database connection pooling mechanism research and size, time-out and other aspects of the configuration has been relatively complete, so there is little impact on application services. In addition, because the database operation is too frequent, database connection pool is a just need, not it.


The distinction between using resource pools can play a role in problem isolation. However, too many resource pools can sometimes cause waste of resources. Although the probability of this situation will be smaller, but once there is a real problem, it is not so easy to locate and solve it.


My experience is to differentiate between types of operations (CPU intensive operations, database read and write operations, network IO, hard disk IO, etc.), using different resource pools for different types of operations (such as different thread pools), and for the same type of operations, you can subdivide (such as intranet io, extranet IO, etc.), and use different resource pools as a basis for this.

But all in all, don't use a globally uniform resource pool.

This article is from the "Programming Capricorn Man" blog, make sure to keep this source http://winters1224.blog.51cto.com/3021203/1885296

Two small lessons about resource pooling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.