XRPLF / xrpl.js

A JavaScript/TypeScript API for interacting with the XRP Ledger in Node.js and the browser
https://xrpl.org/
1.2k stars 511 forks source link

When concurrency is used for more than 100 times, API will report "websocket was closed" #903

Closed RyanHubs closed 6 years ago

RyanHubs commented 6 years ago

//****// errors: Q1.when concurrent users increase(maybe 100users/s),I recevied many errors from RippleAPI instance,like this:

2018-05-27T17:03:33.059||server=iZ8vb448nfpi49cy9g56g3Z||pid=23947||level=ERROR||reqid=getLedger(38952669)|| wsreqid=e2c60d6fcd9c48dbad8be0f5cb71a9c6||onUpdateBlockError||code=||message=websocket was closed||stack=[DisconnectedError(websocket was closed)] at WebSocket.onDisconnect (/data/wallet/xrp/node_modules/ripple-lib/dist/npm/common/connection.js:370:24) at Object.onceWrapper (events.js:317:30) at emitTwo (events.js:131:20) at WebSocket.emit (events.js:214:7) at WebSocket.emitClose (/data/wallet/xrp/node_modules/ripple-lib/node_modules/ws/lib/WebSocket.js:211:10) at _receiver.cleanup (/data/wallet/xrp/node_modules/ripple-lib/node_modules/ws/lib/WebSocket.js:199:39) at Receiver.cleanup (/data/wallet/xrp/node_modules/ripple-lib/node_modules/ws/lib/Receiver.js:520:15) at WebSocket.finalize (/data/wallet/xrp/node_modules/ripple-lib/node_modules/ws/lib/WebSocket.js:199:20) at emitNone (events.js:111:20) at Socket.emit (events.js:208:7) at endReadableNT (_stream_readable.js:1064:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickDomainCallback (internal/process/next_tick.js:218:9)

//****// Q2.When I received to much errors, The node.js process eats a lot of memory,like this: │App name │ id │ mode │ pid │ status │ restart │ uptime │ cpu │ mem │ user │ watching │ │ xrp_server │ 0 │ fork │ 23947 │ online │ 3 │ 25m │ 1% │ 1.7 GB │ admin │ disabled │

So, can you help me to see it? Thank you

RyanHubs commented 6 years ago

@intelliot Can you help me to see it? Thank you

intelliot commented 6 years ago

What rippled server are you using? Are you running rippled yourself? If the server disconnects you, you’ll get that error.

RyanHubs commented 6 years ago

@intelliot yes, I run the rippled server locally(should be Stock server mode). The network topo is: (app users)------(koa2 server)------Rippled(Stock server locally) The rippled.cfg is: https://github.com/LuoRyan/Clearning/blob/d4239fe1a8a6e6869f1fd2acebff8e3f03a72de2/ripple.js#L151-L221

if I run the rippled server locally,how can I solve this problem?

One more question, Should I use "new Remote({ server: wsURL,timeout: wsTimeout})" for every user http request, and disconnect() for receiving the data from rippled server, Like this:

async handler(method, ...options) { await this.remote.connect(); let res = await this.remote [method] (...options); await this.remote.disconnect(); return res; }

Thanks~~

intelliot commented 6 years ago

I recommend using a single connection to rippled, no matter how many users your site has. There’s no need to disconnect.

RyanHubs commented 6 years ago

@intelliot OK,I will use a single connection to rippled, thanks~~

I see this info at: https://developers.ripple.com/rippled-server-modes.html#properties-of-a-good-validator Stock server - follows the network with a local copy of the ledger. Validating server, or validator for short - participates in consensus.

As an exchange, we need history ledger data and sumbit payment.(At present, the Stock server mode we use) In this case, which rippled server mode should we choose? Can you give me some advice?

intelliot commented 6 years ago

Stock server is the correct mode to use.

RyanHubs commented 6 years ago

@intelliot Thank you very much~~~

RyanHubs commented 6 years ago

@intelliot Can you help me to see it? Thank you

topo: AppUsers --->[http]--->koa2Server --->[one instance of RippleAPI]---->RippledServer(local) timeout parameter seems to be invalid, when a concurrent request is more than 100+, a request Hang up occurs for 446160ms c

RyanHubs commented 6 years ago

@intelliot Is it possible that the websocket connection caused a memory leak?

intelliot commented 6 years ago

It’s possible, but I don’t see evidence of a memory leak. Where do you see that?

intelliot commented 6 years ago

@LuoRyan I'm closing this issue, but please let us know if you spot a memory leak.