I'm trying to find a replacement for our inhouse Non-Blocking reactor and so far Netty seems like a good fit. The only thing I couldn't figure out is if there is any throttling support for connections. I'd like to control both the incoming as well as the outgoing rate for individual connections. Is there any support or would I have to write my own throttler on top?
take a look at:
io.netty.handler.traffic
There isn't something like that in netty. But contributions are always welcome ;)
Related
I have a strange szenario:
Webserver / Appserver (Java) sends requests to many different satellite systems (on customers site). Only satellite systems can initiate connection due to firewall rules.
The model I think should be something like REQ/REP, but here the REQuester have to bind and the REPlyer would have to connect.
Is this possible and a stable architecture?
Are there better solutions? (We first had WebSockets in mind...)
Remark: we don't have to use Java on both ends. To be precise on customers site we have Delphi, but we could bridge it somehow.
The model I think should be something like REQ/REP, but here the
REQuester have to bind and the REPlyer would have to connect.
This will be problematic. When the server initiates the connection, it must be aware of all peers and their bind address. Not a big deal for a handful of peers, but for many peers changing constantly, it's a mess.
Only satellite systems can initiate connection due to firewall rules.
If that's the case, your mileage will vary with WebSockets; google around, lots of info on this.
Are there better solutions?
Well, with ZeroMq, one solution that comes to mind to support client request initiation is this:
Server binds with ROUTER
Clients connect with DEALER.
This approach offers bi-directional request/reply, does not block (asynchronous), and eliminates the client-side bind problem mentioned in your question. Here, the server binds, and either side can initiate the conversation.
I recommend reading this section in the guide, it covers extended async request/reply and message enveloping, important when using ROUTER/DEALER sockets.
I'm looking for an IMAP client library or parser that can support asynchronous I/O. The end goal being I could have dedicated thread(s) do socket I/O (via a poll() loop or similar) and could send data to waiting clients/parsers, as it becomes available. All of the code/libraries I've seen to date (java.mail, Python's imaplib, Thunderbird's C++ IMAP client, many random ones in C, C++) seem to follow the traditional blocking, one-thread-per-socket approach, which won't work for me.
My ideal client or library would behave much like https://github.com/ry/http-parser in that I/O behavior would not be dictated by the IMAP bits. Instead, the IMAP library would deal with buffers/strings and the caller would manage I/O.
The only possibility I've seen so far is libcurl. But, I'm not sure if the API will work and want to look at other possibilities before going too far down that road or inventing my own solution.
I'm open to considering libraries in any programming language.
Twisted (http://twistedmatrix.com/) has an asynchronous IMAP4 client: twisted.mail.imap4.IMAP4Client
People sometimes say that this protocol is difficult to implement, so implementation quality may be an issue. The defunct Chandler project used the twisted IMAP4 client, and its source code contains the comment "This functionality will be enhanced to be a more robust IMAP client in the near future".
I've had great results with node.js for this kind of thing. If listening to a lot of open sockets you'll need to tweak some linux settings to increase limits for the number of open file discriptors but it works great.
Would Nitrogen Project's COMET be comparable to ejabberd's xmpp in stability and amount of open connections it can hold? I'm interested in seeing how much of a load Nitrogen can hold. If anyone has any data on this they'd like to share I'd greatly appreciate it.
I do not know much about Nitrogen's COMET implementation, but the ejabberd XMPP comet implementation works over a protocol named BOSH, which basically wraps around XMPP stuff to give some state to HTTP.
BOSH has many interesting aspects that can end up making it somewhat annoying for lots of connections: it can only support one active connection per user at once (due to some hashing scheme to ensure message ordering required by XMPP), unless you try and wrap the protocol in something else, at which point you'll just be writing your own COMET stuff.
So unless you do need XMPP, going with any other implementation might be better in the long run. If you do need XMPP, I believe the difference will be minimal and that you might end up writing a BOSH-like protocol yourself.
Note that how many connections can be held will also depend on what your own application will do on the server, not just the socket handling.
I am implementing some networking stuff in our project. It has been decided that the communication is very important and we want to do it synchronously. So the client sends something the server acknowledges.
Are there some general best practices for the interaction between the client and the server. For instance if there isn't an answer from the server should the client automatically retry? Should there be a timeout period before it retries? What happens if the acknowledgement fails? At what point do we break the connection and reconnect? Is there some material? I have done searches but nothing is really coming up.
I am looking for best practices in general. I am implementing this in c# (probably with sockets) so if there is anything .Net specific then please let me know too.
First rule of networking - you are sending messages, you are not calling functions.
If you approach networking that way, and don't pretend that you can call functions remotely or have "remote objects", you'll be fine. You never have an actual "thing" on the other side of the network connection - what you have is basically a picture of that thing.
Everything you get from the network is old data. You are never up to date. Because of this, you need to make sure that your messages carry the correct semantics - for instance, you may increment or decrement something by a value, you should not set its value to the current value plus or minus another (as the current value may change by the time your message gets there).
If both the client and the server are written in .NET/C# I would recommend WCF insted of raw sockets as it saves you a from a lot of plumbing code with serialization and deserialization, synchronization of messages etc.
That maybe doesn't really answer your question about best practices though ;-)
The first thing to do is to characterize your specific network in terms of speed, probability of lost messages, nominal and peak traffic, bottlenecks, client and server MTBF, ...
Then and only then you decide what you need for your protocol. In many cases you don't need sophisticated error-handling mechanisms and can reliably implement a service with plain UDP.
In few cases, you will need to build something much more robust in order to maintain a consistent global state among several machines connected through a network that you cannot trust.
The most important thing I found is that messages always should be stateless (read up on REST if this means nothing to you)
For example if your application monitors the number of shipments over a network do not send incremental updates (+x) but always the new total.
In a common think about network programming, I think you should learn about :
1. Socket (of course).
2. Fork and Threading.
3. Locking process (use mutex or semaphore or others).
Hope this help..
I have a server and some clients (about 50) in an intranet. The clients send short (about 40 character) string data to the server and the server answers with a similar string. There are up to (but not permanently) 2-3 requests per second for each client. The server has to serialize the requests to get the response strings.
The system should have as less as possible impact on the network as possible (i.e. the server may run something like a webserver already). It should be as easy to install and administer as possible.
What are the possibilities to achieve this using Delphi (Client: D7, Server up to D2010)?
I use the Synapse library for such a simple server. Its lightning fast, very light, and threads easily. The demo Echo in the main synapse install is a fantastic start for what your trying to do. If you are going to be performing database access inside each request/response thread then I strongly also suggest looking at the connection pool example by Cary Jensen to keep your database connections in check.
TCP, definitely. But I'd like to give a vote for ICS. Never liked Indy ...
What about Indy's TIdTCPServer and TIdTCPClient? They provide command handlers, which makes implementing text-based protocols very straight-forward.
There are a lot of options.
Ultimately, I agree with Smasher and like using sockets. They're quick, easy and portable. If you're dealing with a fairly simple protocol and don't need a full n-tier solution, creating a TCP or HTTP server application is dead simple, very light weight, and easy to make compatible with any client. You can even add SSL support to these stand alone applications without having to configure a web server or interfering with it, if it's already running on the same box.
I use RemObjects SDK for this sort of purpose. It takes care of all the difficult stuff, and I just ask it to connect and make function calls to pass the data.