#1 2019-02-28 06:43:45

chapa
Member
Registered: 2012-04-30
Posts: 117

THttpApiWebSocketServer Features Requests

Hello ab,

I would like to share some thoughts about WebSocketServer, as I am about to run it on production server, and face some problems which I am workarounding but is better to be handled by the framework itself.

1. New callbacks for OnPing and OnPong frames. Let us define our App logic around this mechanism. Very handy when measuring connection speed, as sending messages over slow connections easy fills http.sys kernel side entity cache. When it happen it closes underlying TCP connection, which leads to problems to the web socket client and THttpApiWebSocketServer itself. Pinging client and waiting for pong response every XXX kb transferred until we continue with transfers is an easy fix.
2. Better handle Http.ReceiveRequestEntityBody and Http.SendResponseEntityBody for errors, eg.  ERROR_NETNAME_DELETED for read, which often precedes ERROR_CONNECTION_INVALID for write, when underlying tcp connection broke.
3. Better synchronization of TSynWebSocketGuard actions. When I used to run it, I often end with application process being terminated with "Faulting module name: KERNELBASE.dll". Further investigation shows:
STACK_TEXT: 
KERNELBASE!RaiseException+0x68
websocket!ReportFatalException+0x74
websocket!WebSocket_invalid_object_handle_fatal_error+0x32
websocket!WebSocket::VerifyCookie+0x1c
websocket!WebSocketSend+0x24
Debugging shows it happens when guard close the connection and handle to the websocket is set to nil, but TSynThreadPoolHttpApiWebSocketServer.Task still try to do number of WebSocketAPI operations over a nil handle
4. If possible some mechanism to wait until http drain its response entity body, like socket flush

Will stop here smile

Thanks.

Offline

#2 2019-02-28 18:11:31

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,570
Website

Re: THttpApiWebSocketServer Features Requests

@chapa - me and Vadim contribute THttpApiWebSocketServer to mORMot, but as far as I understand it not used by mORMot framework itself. So it just a "stay-alone" implementation.

We used it in production for several years to send notifications to browser clients (one way). But after migration to Linux as a primary OS for our solutions we do not use it anymore.  Since current thread based implementation of TWebSocketServer don't feet our needs (1000 - 10000 connections) we switch to RabbitMQ with websocket plugin for our notifications task (btw it give for us a message persistent layer).

So, (may be @ab correct me..) - contribution is welcome.

Offline

#3 2019-03-01 12:40:14

pvn0
Member
From: Slovenia
Registered: 2018-02-12
Posts: 211

Re: THttpApiWebSocketServer Features Requests

mpv wrote:

@chapa - me and Vadim contribute THttpApiWebSocketServer to mORMot, but as far as I understand it not used by mORMot framework itself. So it just a "stay-alone" implementation.

We used it in production for several years to send notifications to browser clients (one way). But after migration to Linux as a primary OS for our solutions we do not use it anymore.  Since current thread based implementation of TWebSocketServer don't feet our needs (1000 - 10000 connections) we switch to RabbitMQ with websocket plugin for our notifications task (btw it give for us a message persistent layer).

So, (may be @ab correct me..) - contribution is welcome.

Is there any good opensource FPC/Delphi library for RabbitMQ other then what is available commercially ?

Offline

#4 2019-03-01 16:16:32

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,570
Website

Re: THttpApiWebSocketServer Features Requests

Offline

#5 2019-03-02 09:48:41

chapa
Member
Registered: 2012-04-30
Posts: 117

Re: THttpApiWebSocketServer Features Requests

@mvp
Looking at http.sys websocket implementation, I feel it very close and native to me, as I remember well back on 2013, when I fight making it work. I would like to give it a try with mormot, and already had adopted it, now serving real-time communication between internal services stable, at extremely high rate and no latency. So, thank you very much for your and Vadim contribution, now it is not sitting in the corner smile

Speaking about it, I was always wondering about migrating on Linux. Recently was reading a lot about RabbitMQ also.
But I did not felt comfortable going this way. I am stuck with Window's SRWLock, ConditionVariables, Queues. Will have hard time moving all of them, and to be honest, I am very satisfied about their performance.

I am very keen to ask you about your impression, pros and cons migrating services to linux, and rabbitmq performance itself in terms of throughput and latency? I am sure you put it on a stress smile

Last edited by chapa (2019-03-02 09:52:47)

Offline

#6 2019-03-02 17:58:28

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,570
Website

Re: THttpApiWebSocketServer Features Requests

SRWLock exists in posix threads, so this is not a problem

thread_rwlock_rdlock(p);
thread_rwlock_unlock(p);
...
thread_rwlock_wrlock(p);
thread_rwlock_unlock(p);

But I don't know about it performance.

RabbitMQ for example used in World Of Tank, so I think it's performance is enough for most task. We use in one of our hi-load IoT project w/o problem. Now we plane to use it as a service bus for integration.

Our goal of migration to Linux not in performance and even not in cost but in security, deployment and maintaining. From this POW it's nothing to compare Linux and Windows. It's like compare BMW & Lada Kalina smile And after 1 year with Linux I fully agree with nginx author - see the last paragraph in this article

Last edited by mpv (2019-03-02 19:03:04)

Offline

#7 2019-03-02 21:09:04

emk
Member
Registered: 2013-10-24
Posts: 96

Re: THttpApiWebSocketServer Features Requests

@pvn0 search for "delphi amqp".
Kbmmw also has an Amqp 0.91 library.

Offline

#8 2019-03-03 13:29:48

emk
Member
Registered: 2013-10-24
Posts: 96

Re: THttpApiWebSocketServer Features Requests

mpv wrote:

we switch to RabbitMQ with websocket plugin for our notifications task

Which websocket plugin? (Web-stomp?) It's reliable? Any experience to share?

Last edited by emk (2019-03-03 13:37:19)

Offline

#9 2019-03-03 13:49:28

mpv
Member
From: Ukraine
Registered: 2012-03-24
Posts: 1,570
Website

Re: THttpApiWebSocketServer Features Requests

Yes, web-stomp It's "just worlk"

Offline

Board footer

Powered by FluxBB