juks / iso-8583-socket-queue

ISO 8583 gateway
MIT License
195 stars 111 forks source link

Is queue based approach right for ISO gateway? #26

Closed VictorDusautois closed 6 years ago

VictorDusautois commented 6 years ago

Hi Juks,

SocketQueue is really a great solution based on Nodejs and we tried testing a few implementation. All seems good except for this queuing mechanism which we would like to know the reason for.

Currently if we send 10 concurrent requests using REST on listenHttpPort, we realised that it gets queued on the Socket Queue. If each transaction is taking around 10 seconds (Upstream takes this time), it's executing the requests sequentially and takes almost 100 seconds to complete 10 requests.

So is it by design it's suppose to queue the transactions and execute sequentially or is it some kind of configuration which can be disabled so that concurrent requests could be served in parallel?

juks commented 6 years ago

Hi Victor!

The queue approach is the result of mPOS startups reality: you have a merchant ID together with one of few terminal IDs (TID). But your customers might have more points of sale, more messengers. Even if you ask your bank for more — it might be not always possible to get. Only one message with the same TID can be processed by payment systems at a time. So, in case there are two messages with one TID — they will get queued.

Basically you right: 10 requests, made by one terminal will take up to 10 * timeout seconds to complete. In case there will be messages with different TIDs, they will be passed to the upstream one by one immediately, then responses will get dispatched in order and at the time of appearance.

You may see this in action by running:

nodejs socketQueue.js --upstreamHost=localhost --upstreamPort=5000 --listenPort=2014 --vv --echoServerPort=5000 --testTargetHost=localhost --testTargetPort=2014 --testClients=100
VictorDusautois commented 6 years ago

Hi,

That really makes sense. Even from an ATM terminal only one transaction can be carried out at a time. And if the TID is different as you said it will be executed concurrently then there is no issue.

Just being curious, could you point to the files which is validating TID for queuing purpose? If i want to test concurrency from same terminal (TID), will it be much difficult to change the code and remove TID validation for Queueing? If you could just guide on which files it's validating I could give it a try from my end.

juks commented 6 years ago

Victor, there is queueLockTerminal parameter that does the job.

For the sake of curiosity, please see here: https://github.com/juks/SocketQueue/blob/2f7b6519fce1c615be84ffdd672dae8cdbb35878/lib/iso8583-queue/lib/iso8583Queue.js#L132