0
這裏分享的話:文件系統通過multiprecoesses與多線程
I am talking about general linux concurrent programming environment
Definition:
Node: a machine with a processor.
file system: can be accessed both locally and remotely.
it includes large set of files varied in random size.
Node I: Process A with multithreads access A's file system, operations include
read and write. Process B, similar to A. Think about more similar processes
C,D,etc.
Then, thinking about scaling. The same FS system is located on a separate node.
Operated by processes E,F,G etc on node II, and processes A,B,C,D on Node I.
thinking about similar node III,IV,V, etc.
這既是一種實用的面試問題。這裏是我的解決方案:
I can use mutex and signal resolve multi reader and writer of the same
file within a process. And also using IPC resolve multiprocesses
communication and synchronization.
the code could work very well for single node multiprocesses.
But, when dealing with multi node. We need similar but more
complicated mechanism to detect are there any node
writting on the FS, if yes, wait; otherwise, access
writting mutex and write, then notify waiting guys.
經過思考,如下是我的想法:
From the point of a NFS, we define file lock of course based on file.
My target is:
at each moment,there is only one writer write the file,
there can be more than one reader read the file.
Then, all the processes on different nodes are the same.
they should have their own mechanism to acquire either read or write lock,
of course, dealing with connection, failures and retries.
我想知道是否有一些原型爲這樣那樣的問題呢?
我認爲節點間同步可能是多個節點訪問共享NFS的一個解決方案。同樣,如果自上次讀取後沒有更新,則一個消費節點可能會暫停讀取。另一位消費者在更新文件後可能會恢復此節點。我認爲解決方案有點複雜。 – SecureFish
如果您有生產者和消費者進行通信,您可能需要查看某種形式的[消息傳遞接口(MPI)](http://en.wikipedia.org/wiki/Message_Passing_Interface)(例如[MPICH](http: //www.mcs.anl.gov/mpi/))。 –