views:

174

answers:

9

Suppose there is a System A which gives some output. This output is used as input by system B. The rate at which System A produces is faster than the rate at which system B consumes it. How can we implement this?

The System A sends video at 10mbps where system b can take up only 4mbps.how we can implement this.Also there should be continous streaming of video? communication happens thru socket. tcp/ip.

anybody know the logic in java ? there is a double buffer solution? i dont know.

A: 

Well you either improve it or not, or you have system B wait for system A to send message or whatever .. you can use threads for that for waiting. Maybe if you could provide more details, someone would be able to answer. If you say how can I improve system B, what you want us to respond, we don't know anything about either system.

c0mrade
A: 

Improving system B performance or decreasing system A performance :-)

SourceRebels
+3  A: 

This is known problem called Producer-Consumer: http://en.wikipedia.org/wiki/Producer-consumer_problem You can use threads as you question suggests - you can have System A run in different thread and when it makes sense, you can make that thread sleep. Other solution, known from hardware, could be to use a buffer, intermediary memory.

Gabriel Ščerbák
+1  A: 

That depends. If System A continuously produces more output than System B can handle, you have two options:

  • Improve System B to handle the load System A produces
  • Implement an intermediary System C that handles the output from System A, aggregates this output and presents it in a form that System B can handle.

If the rate at which System A produces output is temporarily larger than the rate at which System B can handle it, you should implement a queueing solution. System A stores its output in a queue and System B pops items of the queue.

Ronald Wildenberg
+1  A: 

If you study operating systems, telecommunications, or electronics, you'll learn that buffers are good for this.

They can be an elastic way to cope with temporary differences in speed. If the speed difference is permanent, and the buffer has a finite size, then System A will eventually have to pause or risk losing its output.

John
thanks john ,they are using advanced buffer concept ,specifically in protocols.i want to know the concept of this. can anybody from pure bit level programming help me out. helpful for my career.
Suresh S
Double buffering is a completely different concept for animations: display one buffer while you modify another, and then swap them over. Don't worry about this concept for communications.The Java producer consumer tutorial should be a good place to learn: http://java.sun.com/docs/books/tutorial/essential/concurrency/guardmeth.html
John
A: 

You can use a solution like Java Messaging Service (JMS).

http://java.sun.com/products/jms/

This allows asynchronous communication via message queues. System A and B are completely independent from each other and do not have to process messages at the same speed.

Eric Eijkelenboom
+1  A: 

There are 2 distinct cases:

  • System A permanently generates data faster than can be processed by B
  • System A produces data in batches; averaged over e.g. a day it is less than B can handle

The second case can be solved by queueing (JMS), the first case is more difficult.

If you can scale up the hardware on B sufficiently, than that would be the way to go.

You could optimize the slowest part of B (optimize the code), but you'd have to do all kinds of testing again.

You could check if you can work with multiple B's (load balancing), but the application should support that (multiple instances updating the same data in the DB is not good:).

It all depends on the specific load distribution and the architecture of the apps.

extraneon
A: 

Too general question. I suggest to review these frameworks: Apache Camel, Spring Integration

eugenn
A: 

How is the output of System A provided to System B? If they are in different JVM's you could use an Operating System pipe. Something like:

java SystemA | java SystemB

The OS will suspend SystemA automatically when it gets too far ahead of SystemB. If they're in the same JVM, use can use PipeInputStream and PipeOutputStream to achieve the same thing.

If the output of SystemA is not a stream then you'll have to use some kind of structured data approach as suggested in other answers.

Adrian Pronk
thanks adrain , but i need the logic of how pipe knows the system b's limitation.
Suresh S