Code Monkey home page Code Monkey logo

sharmipc's Introduction

SharmIPC .NET

Image of Build Image of Build Image of Build NuGet Badge Image of Build

Inter-process communication (IPC engine) between 2 partner processes of one OS:
- .NET 4.5 > /.NETCore 2.0 / .NETStandard 2.0 . Based on memory-mapped files
- Written on C#
- Fast and lightweight
- Sync and Async calls with timeouts
- a la RPC
- a la send and forget

===================== Usage example:

//Process 1 and Process2

tiesky.com.SharmIpc sm = null;

void Init()
{
	if(sm == null)
	  	sm = new tiesky.com.SharmIpc(
		  	"My unique name for interpocess com in the OS scope, must be the same for both processes"
		  	, this.RemoteCall
			
			//unique name must start from the prefix "Global/" to make communication available 
			//	for processes executed by different OS users
			
		  	//there are also extra parameters in constructor with description:
		  	//optional send buffer capacity, must be the same for both partners
		  	//optional total not send messages buffer capacity
			
	  	);
  	
  
  	
  	
}

void Dispose()
{
	//!!!For the graceful termination, in the end of your program, 
  	//SharmIpc instance must be disposed
  	if(sm != null){
  		sm.Dispose();
  		sm=null;
  	}
}

Tuple<bool,byte[]> RemoteCall(byte[] data)
{
		//This will be called async when remote partner makes any request
		
		//This is a response to remote partner
		return new Tuple<bool,byte[]>(true,new byte[] {1,2,3,4});	
}

void MakeRemoteRequestWithResponse()
{
	 //Making remote request (a la RPC). SYNC
	 Tuple<bool,byte[]> res = sm.RemoteRequest(new byte[512]);
	 //or with callback
	 //var res = sm.RemoteRequest(data, (par) => { },30000);
	 
	 //if !res.Item1 then our call was not put to the sending buffer, 
	 //due to its threshold limitation
	 //or remote partner answered with technical mistake
	 //or timeout encountered
	 if(res.Item1)
	 {
	 		//Analyzing response res.Item2
	 }
}

// async/await pattern
async void MakeRemoteRequestWithResponse()
{
	 //Making remote request (a la RPC). SYNC
	 //Non-blocking current thread construction!
	 Tuple<bool,byte[]> res = await sm.RemoteRequestAsync(new byte[512]);
	 //or with callback way
	 //var res = await sm.RemoteRequestAsync(data, (par) => { },30000);
	 
	 //if !res.Item1 then our call was not put to the sending buffer, 
	 //due to its threshold limitation
	 //or remote partner answered with technical mistake
	 //or timeout encountered
	 if(res.Item1)
	 {
	 		//Analyzing response res.Item2
	 }
}

void MakeRemoteRequestWithoutResponse()
{
	 //Making remote request (a la send and forget)
	 Tuple<bool,byte[]> res = sm.RemoteRequestWithoutResponse(new byte[512]);
	 
	 if(!res.Item1)
	 {
	 	//Our request was not cached for sending, we can do something
	 }
}

//----starting from v1.04 it's possible to answer on remote call in async way:

//New way of instantiation of SharmIPC 
//sm = new tiesky.com.SharmIpc("MyUniqueNameForBothProcesses",this.AsyncRemoteCallHandler);

//where AsyncRemoteCallHandler will be used instead of RemoteCall and gives an ability to answer to 
//the remote partner's request in async way

void AsyncRemoteCallHandler(ulong msgId, byte[] data)
{
        //msgId must be returned back
        //data is received from remote partner
        
        //answer to remote partner:
        sm.AsyncAnswerOnRemoteCall(msgId, new Tuple<bool, byte[]>(true, new byte[] { 5 }));
         
       
}

===================== Benchmarks:

[DLL size is 15 KB]

[512 bytes package in both directions]
Remote async and sync calls with response (a la RPC), full-duplex, with the speed of 20 MB/s.
Remote async calls without response (a la send and forget), full-duplex, with the speed of 80 MB/s.

[10000 bytes package in both directions]
Remote async and sync calls with response (a la RPC), full-duplex, with the speed of 320 MB/s.
Remote async calls without response (a la send and forget), full-duplex, with the speed of 700 MB/s.

[1 byte package in both directions]
Remote async and sync calls with response (a la RPC), full-duplex, with the speed of 40000 call/s.
Remote async calls without response (a la send and forget), full-duplex, with the speed of 120000 calls/s.

and if you need more speed, just add in both processes more SharmIPC instances

---- Check also our DBreeze database for .NET ----

[email protected]

sharmipc's People

Contributors

hhblaze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharmipc's Issues

lose package or wrong order

I have two process, A send package, B receive package.
I use RemoteRequestWithoutResponse function to send package.
(a package is 389 byte)
The issue is, it lost some package or wrong order sometimes.
(both of 1.16 and 1.17 )

SharmIPC not working within a service

Hello,

to me it looks like SharmIPC won't work when the implementation is run as a service. I usually have a project with the implementation, accompanied by a console project (for testing) and the service project. Normally the first started console project registers as a MASTER and the second console project as a SLAVE. When running these projects as a service they don't seem to know each other. Both of them register as MASTER and they can't communicate. Is there any solution to this?

Missing eProtocolVersion

Hi, this looks like a VERY nice package, thank you.
When I install from Nuget, the latest 1.16.0, and try to do the new() in your examples, tiesky.com.SharmIpc.eProtocolVersion is not recognized and gives a compile error. When I instead reference your SharmIpc.dll directly (SharmIpc462, built from git clone) the enum is recognized, no build issues.
Best regards,
Dale

Issues when creating many new instances quickly

I have a simple app that spins up 100 processes as test and tests some messages going back and forth as i was building it up to test concurrency before i integrate the wrapper around SharmIPC i build to auto serialize and deserialise my classes as well as manage all the processes.

What i found is that if i spin up a lot of processes instantly a large number will of the SharmIPC Slaves will fail to send the first message i try to send. This message is a hartbeat and notification the child process has started so if it fails my child process shuts down. Interesting thing i found is the more i delay the start up of each new process the more child processes work successfully. For example at a 1 second delay 50/100 will start and send first message without error but at 2 second delay then 75/100 will start successfully and send first message.

Is there any know limits here? I can see the messages that the master and slave have started in console even though there is no way to check it on the IPC instance itself. All i get back the the false for it failing to send and it does not arrive on the receiving side.

Debugging has not helped too much yet and i need to find a way to get the actual error.

I can't say for sure it is not Anti virus or something on my computer causing this but thought i would check first if i am hitting some known issue.

Does this work on Mono?

I could not get this project to work correctly under Mono, please can you confirm that this works on Mono? I am testing under Mono 4.2.1 using Ubuntu 16.04 LTS.

The Mutex, as implemented on Mono does not provide the same inter-process synchronization like it does on Windows going back as far as version 2.8.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.