Commit Graph

7 Commits

Author SHA1 Message Date
Wladimir J. van der Laan c7f77e28f0 http: speed up shutdown
This continues/fixes #6719.

`event_base_loopbreak` was not doing what I expected it to, at least in
libevent 2.0.21.
What I expected was that it sets a timeout, given that no other pending
events it would exit in N seconds. However, what it does was delay the
event loop exit with 10 seconds, even if nothing is pending.

Solve it in a different way: give the event loop thread time to exit
out of itself, and if it doesn't, send loopbreak.

This speeds up the RPC tests a lot, each exit incurred a 10 second
overhead, with this change there should be no shutdown overhead in the
common case and up to two seconds if the event loop is blocking.

As a bonus this breaks dependency on boost::thread_group, as the HTTP
server minds its own offspring.

Zcash: cherry-picked from commit a264c32e3321ae909ca59cb8ce8bf5d812dbc4e1
2017-08-01 20:24:27 +01:00
Jack Grigg 689264bbff
Add test for issue #2444
A WWW-Authenticate header must be present in the 401 response to make clients
know that they can authenticate, and how.
2017-07-12 16:34:58 -05:00
Wladimir J. van der Laan 89bccddcd8
rpc: Split option -rpctimeout into -rpcservertimeout and -rpcclienttimeout
The two timeouts for the server and client, are essentially different:

- In the case of the server it should be a lower value to avoid clients
clogging up connection slots

- In the case of the client it should be a high value to accomedate slow
  responses from the server, for example for slow queries or when the
  lock is contended

Split the options into `-rpcservertimeout` and `-rpcclienttimeout` with
respective defaults of 30 and 900.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 116503c0b8
Fix race condition between starting HTTP server thread and setting EventBase()
Split StartHTTPServer into InitHTTPServer and StartHTTPServer to give
clients a window to register their handlers without race conditions.

Thanks @ajweiss for figuring this out.
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 9fb5b94e64
Document options for new HTTP/RPC server in --help 2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan 858afa1a4a
Implement RPCTimerHandler for Qt RPC console
Implement RPCTimerHandler for Qt RPC console, so that `walletpassphrase`
works with GUI and `-server=0`.

Also simplify HTTPEvent-related code by using boost::function directly.

Zcash: QT changes ommitted
2017-03-24 09:03:59 +13:00
Wladimir J. van der Laan afd64f76ea
evhttpd implementation
- *Replace usage of boost::asio with [libevent2](http://libevent.org/)*.
boost::asio is not part of C++11, so unlike other boost there is no
forwards-compatibility reason to stick with it. Together with #4738 (convert
json_spirit to UniValue), this rids Bitcoin Core of the worst offenders with
regard to compile-time slowness.

- *Replace spit-and-duct-tape http server with evhttp*. Front-end http handling
is handled by libevent, a work queue (with configurable depth and parallelism)
is used to handle application requests.

- *Wrap HTTP request in C++ class*; this makes the application code mostly
HTTP-server-neutral

- *Refactor RPC to move all http-specific code to a separate file*.
Theoreticaly this can allow building without HTTP server but with another RPC
backend, e.g. Qt's debug console (currently not implemented) or future RPC
mechanisms people may want to use.

- *HTTP dispatch mechanism*; services (e.g., RPC, REST) register which URL
paths they want to handle.

By using a proven, high-performance asynchronous networking library (also used
by Tor) and HTTP server, problems such as #5674, #5655, #344 should be avoided.

What works? bitcoind, bitcoin-cli, bitcoin-qt. Unit tests and RPC/REST tests
pass. The aim for now is everything but SSL support.

Configuration options:

- `-rpcthreads`: repurposed as "number of  work handler threads". Still
defaults to 4.

- `-rpcworkqueue`: maximum depth of work queue. When this is reached, new
requests will return a 500 Internal Error.

- `-rpctimeout`: inactivity time, in seconds, after which to disconnect a
client.

- `-debug=http`: low-level http activity logging
2017-03-24 09:03:59 +13:00