views:

546

answers:

6

i have to build a concept to communicate between two computers using shared memory or tcp socket programming concepts..how do i go about it?is it possible to implement shared memory in a client server architecture?how do i go about it?

+7  A: 

You can't communicate between two computers using shared memory, because they don't share memory.

You should use TCP sockets.

Zifre
You can do it on flash stick :)
Prankster
I have a feeling mayank knows that out of the box two computers don't share memory - "is it possible to implement shared memory in a client server architecture? how do i go about it?" The answer is "yes, its possible, look up distributed shared memory"
Mo Flanagan
Distributed shared memory is much harder (and slower) than sockets.
Zifre
That is a very broad statement isn't it? Products like gemstone and gigaspaces are distributed caches built on top of UDP / TCP, its not some either/or thing.
Mo Flanagan
Please be elbarate in answers, in my gut feeling, mayank must be knowing what you're saying .. may be wrong in the way he asked
Vadi
+1  A: 

I think rather than shared memory, what you are looking for is more properly called something like "reflective memory".

With Reflective Memory blocks each computer on the network owns a block of memory. Every block is punted around a bus between all the computers at a high rate of speed. Each computer gets a copy of the memory from all other computers for reading, but typically can only write to its own memory.

Thus each computer can "see" the state of the memory in every other computer. Typically you see this sort of architecture in industrial control systems that distribute the control over physically separate machines and want to see the overall state in near real-time.

As for building a system, well you could start with UDP packets that just blast out the state of the local computer and have all the other computers read that data.

Peter M
A: 

The snarky answer "you can't do it because computers don't share memory" is just plain wrong. Processors within a single computer do not share memory, the hardware and software implement shared memory protocols to provide an illusion of shared memory.

Shared memory protocols across processors are very similar to shared memory protocols across computers, its the same problem.

Search for "distributed cache" "tuple space" and "distributed shared memory" it might provide some food for thought. memcached is a very popular open source product you can take a look at.

EDIT: Regarding the comment about "cache coherent architecture". Each processor has its own local cache of memory (L1 cache for example). There is a whole bunch of "stuff" that happens to make this "cache coherent" so that it appears each processor is reading and writing to a shared memory space. The processors are absolutely, positively not writing directly to a single shared memory space. The problem is conceptually the same for shared memory across computers.

Mo Flanagan
This is incorrect. On a cache coherent architecture (like x86), processors on the same computer do share memory.
Zifre
Ok, so what is L1 cache?
Mo Flanagan
The per-processor cache. The processors still share main memory and fill the L1 cache from the same memory location.
Jason Coco
Not only that, but newer Intel processors have a shared L3 cache.
R. Bemrose
Correct, per-processor cache. So the processor reads and writes strictly to the L1 cache and there is a coherency protocol which periodically sends message over a shared bus to synchronize the local cache with the shared cache. *This is distributed shared memory*.
Mo Flanagan
Yes, but this is completely transparent to the OS and programs. It doesn't matter at all how the caches are implemented, as long as memory is coherent.
Zifre
> Processors within a single computer do not share memoryI suspect this is a matter of term definition. CPUs on a single computer certainly do share the same physical memory.
Blank Xavier
@Blank: He's saying that when they have an L1 cache, they don't since date is fetched to the cache on a fault
Jason Coco
@Blank: my point, and I blame myself for not explaining this clearly, is that CPU's on a multi processor machine *do not* write directly to shared memory, there are multiple layers of memory caching. There is a striking similarity between the way you implement shared memory between CPU's and the way you implement shared memory between computers on a high speed shared network.
Mo Flanagan
A: 

You may want to look into something like memcached, a distributed memory object caching system.

Granted, this is still done via TCP.

R. Bemrose
A: 

You CAN communicate with a remote system with shared memory. Remote DMA is a feature of newer high performance network interface controller cards (NIC).

Here's a paper which evaluated 10 Gb ethernet RDMA performance. I know infinaband can also RDMA, others likely. Won't it be nice when 802.11 XXX comes out? Wireless RDMA? :)

RandomNickName42
A: 

I recommend Beej's guide to Network Programming.

Andrioid