Prakash
Prakash

Reputation: 576

Play WS max connection

We have three components(A,B and C). "A" sends data to "B" and "B" process data and post it to "C" using play WS. We have a situation when "C" is slow in processing the data, Time out happens in "B". But there is lot of data inward flow in "B" and keep posting it to "C" causes the whole system to run out of memory and finally crash. Is there a way to limit the number of WS request in "B" ? searched the play WS API but no luck. How should this be handled? Please suggest.

Upvotes: 2

Views: 988

Answers (2)

Hüseyin Zengin
Hüseyin Zengin

Reputation: 1226

The problem is not about max connection number and not anything else api related. This problem is common in distributed systems and named "Fast producer and slow consumer". There is more solution then I could write here but a short list will be:

  • Message Queues (for ActiveMQ see Slow Consumer Handling)
  • BackPressure (this is a method that can be explained with one sentence; "Producer sends data only when consumer asks", BTW, Akka Streams makes this available in an elegant way)
  • Scale (the most straight method if you want your system faster, just increase nmber of your consumers and load balance requests between them or make the consumer faster)

Edit: According to Documentation you can set a max. connection per host or total for client library, as I mentioned above the right way is improving architecture but this may also help and save the day. Also check reference.conf for all configuration options.

Upvotes: 1

Andriy Kuba
Andriy Kuba

Reputation: 8263

Consider Akka and some of throttling algorithms: http://letitcrash.com/post/28901663062/throttling-messages-in-akka-2

Upvotes: 0

Related Questions