Skip to content

Try to increase file descriptor rlimit if necessary - #2568

Merged
gavinandresen merged 1 commit into
bitcoin:masterfrom
sipa:rlimit
Apr 29, 2013
Merged

gavinandresen merged 1 commit into
bitcoin:masterfrom
sipa:rlimit

Conversation

@sipa

@sipa sipa commented Apr 25, 2013

Copy link
Copy Markdown
Member

As the default can be too low, especially on OSX.

@gmaxwell

Copy link
Copy Markdown
Contributor

We should probably be clamping max connections at FD_SETSIZE-MIN_CORE_FILEDESCRIPTORS otherwise you get fun stuff like select becoming crashy.

@jgarzik

jgarzik commented Apr 25, 2013

Copy link
Copy Markdown
Contributor

ACK

1 similar comment
@gavinandresen

Copy link
Copy Markdown
Contributor

ACK

@sipa

sipa commented Apr 26, 2013

Copy link
Copy Markdown
Member Author

@gavinandresen Have you tested whether this compiles on OSX?

@gavinandresen

Copy link
Copy Markdown
Contributor

@sipa : yes, compiles fine, unit tests run, bitcoind -testnet runs on OSX

@gmaxwell

Copy link
Copy Markdown
Contributor

@gavinandresen can you try running

(for i in {1..220000} ; do export bh=./bitcoind getblockhash $i ; for tx in ./bitcoind getblock $bh | grep ' "' | cut -d'"' -f2 ; do ./bitcoind getrawtransaction $tx > /dev/null ; done ; done)

On a OSX mainnet node with this patch and txindex=1 when you get a chance? It should causes about 500 FDs to be used.

@sipa

sipa commented Apr 27, 2013

Copy link
Copy Markdown
Member Author

Refactored the code into a RaiseFileDescriptorLimit in util, and added a windows implementation.
Also added Gregory's suggestion to clamp maxconnections, according to the size of FD_SETSIZE.

Minimal test plan:

  • Start the client with increasingly higher -maxconnections=X values
  • Look for the line "Using at most Y connections (Z file descriptors available)" in debug.log
  • Without specific hard ulimits, requests for up to ~1000 connections should be granted (X=Y), and Z should always be at least 150 higher than Y.

I'd like to see at least some proof that this works on Windows on OSX. For Windows, #2569 is needed to get more than 63 connections.

Comment thread src/util.cpp

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? MSDN says: "Up to 2,048 files can be open simultaneously at the lowio level (that is, opened and accessed by means of the _open, _read, _write, and so forth family of I/O functions). Up to 512 files can be open simultaneously at the stdio level (that is, opened and accessed by means of the fopen, fgetc, fputc, and so forth family of functions). The limit of 512 open files at the stdio level can be increased to a maximum of 2,048 by means of the _setmaxstdio function."

Is the 2048 limit on a lowio level or stdio level? If the later we need to call _setmaxstdio(2048) here?
http://msdn.microsoft.com/en-us/library/6e3b887c.aspx

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit fuzzy, as things don't match exactly, but file descriptors correspond to the lowio level. However, the win32 leveldb implementation uses kernel calls directly, bypassing both stdio and lowio, so we don't actually need to count those. On the other hand, for block and undo files, we do use the stdio level...

As the default can be too low, especially on OSX.
@BitcoinPullTester

Copy link
Copy Markdown

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/ba29a5590bc4479d74454f0b9fdaf007d9d80221 for binaries and test log.
This test script verifies pulls every time they are updated. It, however, dies sometimes and fails to test properly. If you are waiting on a test, please check timestamps to verify that the test.log is moving at http://jenkins.bluematt.me/pull-tester/current/
Contact BlueMatt on freenode if something looks broken.

@gavinandresen

Copy link
Copy Markdown
Contributor

ACK. @gmaxwell : successfully ran (a modified version of) your stress test on OSX with this patch and -txindex=1.

@gmaxwell

Copy link
Copy Markdown
Contributor

ACK.

gavinandresen added a commit that referenced this pull request Apr 29, 2013
Try to increase file descriptor rlimit if necessary
@gavinandresen
gavinandresen merged commit 67f93dc into bitcoin:master Apr 29, 2013
@sipa
sipa deleted the rlimit branch May 3, 2013 18:47
@fanquake fanquake mentioned this pull request May 20, 2013
laudney pushed a commit to reddcoin-project/reddcoin-3.10 that referenced this pull request Mar 19, 2014
Try to increase file descriptor rlimit if necessary
bumbacoin referenced this pull request in bumbacoin/bumbacoin2-source Dec 9, 2016
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants