Coversant, Inc® Enabling the New Dial Tone™

12Jul/100

Coversant® Launches SoapBox™ 2010

Coversant, Inc announces the launch of the SoapBox 2010 product line. The release marks the 5th generation of SoapBox and includes multiple SoapBox Server editions, SoapBox Communicator 2010 and SoapBox SDK Studio. BOSH, Composite sockets, enhanced XML compression, and server extension for multicasting and high performance message archiving highlight latest features to hit the platform.

The complete XMPP solution, SoapBox 2010 extensibility and performance make it the prefect fix applications ranging from Enterprise Instant Messaging (EIM) to a reliable communication backbone in your product.

SoapBox Server® 2010: Powerful. Stable. Complete.™

Coversant’s SoapBox Server® 2010 manages secure XMPP communications across domains and platforms with unmatched performance. The SoapBox Server® is the only XMPP solution scalable to ¼ million concurrent sessions on a single CPU, and which supports real-time interoperability with extraordinary throughput exceeding 120,000 messages per second.

  • Highly Scalable, reliable, and extensible XMPP Server
  • Provides remote management of one or more SoapBox Server instances
  • Provides standards based web collaboration using BOSH
  • Multi-User Chat and Conferencing
  • Active Directory, NT, and LDAP integration
  • Composite Sockets

SoapBox SDK Studio® 2010: Toolkit for the New Dial Tone.™

SoapBox SDK Studio 2010 is the only fully documented, open source, multi-platform SDK for integrating XMPP based communications into existing applications and building .NET XMPP apps that can be deployed to a variety of platforms, including Windows, Linux, Pocket PC, Smartphone and Flash. Development time is streamlined with over 50 code samples, 1000 pages of technical documentation and training. Built-in tracing supports effective debugging and application management.

  • Presentity SDKs for Windows Mobile, Windows, Linux, and Solaris
  • Extension SDK for integrating directly with SoapBox Server
  • Administration SDK for managing local or remote instances of SoapBox Server
  • XMPP Based Communications
  • BOSH
  • Multi-User Chat and Conferencing

SoapBox Communicator® 2010: Rich. Nimble. Easy.™

SoapBox Communicator 2010 is an intuitive secure EIM client application that is ready to use with a single click, connecting users securely with any XMPP-compliant server and across organizational bound­aries. Users can collaborate fully with document sharing and editing in real time. The elegant, user-friendly interface and robust features make it the ideal tool for exchanging ideas.

  • Easy to Use and Easy to Deploy
  • Single Sign On with Windows NTLM and Active Directory
  • SoapBox Communicator Enterprise enables Enterprise wide Broadcasting
  • Create/Join Conference Chats
  • Move Beyond Just Sharing Words
  • One-Window Messaging

Coversant is also currently in beta test of SoapBox 2011, expecting an early release prior to the end of 2010. SoapBox 2011 focus on improved management and scalability with move to Active/Active clustering, additional XMPP clients including, C++ and Java, and a redesigned management console.

For more information about SoapBox 2010 or any other Coversant solutions and service, please contact Coversant at sales@coversant.com or visit the Coversant website at www.coversant.com.

21Jun/100

Coversant Classics: System.ThreadPool and when not to use it

In an upcoming blog, I’m going to be talking about some of the threading issues we ran into when running on systems with a number of processors (4, x, 16). As part of that, I wrote this little section on the pain we’ve suffered through due to the ThreadPool.  Rather than keep it in the already-too-long entry on threading, I figured it could stand on it’s own.

I read a lot of literature on threading, threading patterns, and all sorts of stuff in between. In .Net land, most of the literature that I have read strongly recommends using the system threadpool instead of managing your own threads. This literature then goes on to very strongly recommend against rolling your own thread management code, and emphasizes again and again to just use the system threadpool.

As a direct result of reading this literature, the early versions of the SoapBox Server made extensive use of the system threadpool.

I should take a moment to differentiate between the system threadpool and the IOCP threadpool (which we also use):

  • The system threadpool is made up of (by default) 25 threads per processor and is used internally by the .Net framework for a number of tasks. This pool is leveraged by ADO.Net, by all of the built-in delegate BeginInvoke operations, all of the various timer classes, and so forth. Work items are easily posted to a work item queue, and the threadpool then manages as best it can to get the operations done in the order they were posted. The system threadpool is absolutely vital to the proper operation of the .Net framework.
  • The IOCP threadpool, by contrast, has (sort of) 1000 threads in it and is only used (as far as I know) by the Sockets infrastructure. This threadpool is managed by the IO Completion Port infrastructure within the kernel. A detailed explication of how IOCP works can be found in a number of places on the web.

In a WinSock server application (such as the SoapBox Server) when we get a callback from a socket (from BeginReceive, BeginSend, BeginAccept, BeginConenct, etc), processing is done in the context of an IOCP thread, not a threadpool thread.

In an earlier architecture, we used this IOCP thread to parse Xml coming off the socket into strongly typed classes, and then would put the resulting objects into a work item queue. For quite some time, we naively used the System Threadpool to actually do work against the items in the queue. For a little while, this even worked.

The problem is this: Under heavy load, we would quickly get all 25 threadpool threads busy doing something.  Every once in a while though, our server would hang. To those of us initiated into the Skull and FreeThreading society, we simply go, “Oh, it’s a race condition. No trouble. I’ll fix that this afternoon”. Problem was, it wasn't a race condition. At least not exactly.

After poking around for a bit, we would find all 25 threadpool threads blocked in ADO.NET. The database had returned the values already, but none of our threads had yet awoken. It turns out that the callbacks inside the .Net framework ended up being queued to the threadpool. With no threads available (‘cause we’ve got them all tied up doing work!) the callbacks would never happen, and thus all of our threads are essentially deadlocked.

To make matters worse, our watchdog was setup as a Timer class to get callbacks every 30 seconds. During the callback it would check all the threads that were doing something, and take appropriate action if things were stalled. Any guesses how well the timer callbacks work when the threadpool is out of threads?

We saw this process repeat itself several times across several different sets of circumstances (web service calls, ADO.Net, File system writes for trace logs, etc). Between ADPlus generated minidumps and way too much time staring at Son Of Strike (Why doesn’t Microsoft include managed minidump debugging in VS.NET 2005?!? Why? WHY!?), we decided that using the system threadpool is simply not an option.

The bottom line is this: For production grade server applications do not use the system threadpool. The issue of thread starvation and the assumption by the CLR that it can always use the threadpool make it something that cannot be used by a robust server class application.  Applications that do depend on it are at major risk of hanging.

Now, for small apps, and client side code I love the threadpool. It’s great. For server apps it’s deadly.

As a result of this, we have rolled out own threadpool. This is something that sounds easy at first, but is quite hard. I really wish the CLR exposed the ThreadPool class, as it would make things much easier.

I would love to be able to say, “Threadpool _processingPool= new Threadpool();”

Getting things like thread affinity, thread creation, thread destruction, and all the other little details juuuuuust right is very, very hard.

I had a few conversations with Jeff Richter about this topic, and it was his assertion that's it's not the threadpool that's broken here, but rather our architecture. He is of the opinion that the critical flaw is that we're doing synchronous operations while running on threadpool threads. This can cause timeout and deadlock issues just like we're seeing.

A problem arises in that we need to perform database operations in response to packets sent to us by clients. Richter's answer: Perform aync database operations, make sure everything else is async, and use nothing but threadpool threads. This will increase scalability, reliability, throughput, and everything else. At a very fundimental level, I believe him. His arguments are very persuasive.

At first glance, making the database async will work. SQLClient has support for this with BeginExecuteCommand, and this should do the trick. Things even appear to be IOCP enabled, which is a great bonus. Problems quickly arise though:

- The only ADO.Net provider that supports the Begin/End pattern is SQLClient. This means we're out of luck for Oracle, MySQL, and Postgre. If we're going to do this, it means special casing our database support. Not a showstopper, but certainly a pain.

- The showstopper is that SQLClient only partially supports async operations. There is no "SqlConnection.BeginOpen"!! This means that we're always stuck synchronously opening database connections. As soon as we exhaust the connection pool (25 connections or so, by default), whatever thread is trying to perform a datbase I/O will block waiting for a connection. I would be stuck writing our own connection pooling mechanism, tying it to IOCP, and then managing everything. Ick.

As a result of the inability to perform async database operations at any reasonable scale due to the lack of a BeginOpen method on SqlConnection, I am forced to restate my original premis with a slight modification:

Don't use the Thread Pool if you have to perform any synchronous I/O. Because all signifgiant applications need to perform database access, which must be synchronous, you can't use the ThreadPool in any signifigant server applications.

I suppose there are special case applications where you could post database operations to a Message Queue using async operations. These messages would then be dequeued, and executed. The results posted back to the queue for the application to pick up. For Write-Only operations this seems like it would be a good way to go - for anything else it's not much of an option.

14Jun/100

Coversant® Restablises Partnership with XSF

Coversant® executives join XMPP Standards Foundation:

Coversant, Inc's  Chief Software Architect Dave Richard and Director of Business Development Eero Neuenschwander joined XMPP Standards Foundation (XSF) on April 28th, 2010. Dave and Eero will work closely with other XSF members to enhance XMPP and Coversant's ability to provide the best communications platform in world.

Dave will be a member of the XSF Technical Review Team which is responsible for continuous improvement of the technical quality of specifications produced by the XMPP Standards Foundation. Dave brings 18 years past protocol experience to the XSF highlighted by:

  • Contributions to the ASHRAE BACnet specification (86441 - Standard 135-2008 -- BACnet – A Data Communication Protocol for Building Automation and Control Networks (ANSI Approved)) in the form of technical discussion and review since 1996
  • A founding member of the oBIX group at OASIS
  • Served as the chair of the oBIX XML technical committee for a year and a half until February 2010 when I left the company through whom I was an OASIS member.
  • Contributions to Wireshark (starting back in the Ethereal days circa 2002)

Eero will be member of XSF Communications Team and support the overall communities growth, by promoting XMPP viability as communication medium for more than just instant messaging. With Product Management as well as Sales and Marketing responsibilities at Coversant, Eero can ensure customer needs are considered as future enhancements to the specification are discussed and ratified.

For more information about Coversant involvement with the XSF and other organization, please contact Eero at eneuenschwander@coversant.com.

7Jun/100

Coversant Classic: How to Build Scalable .NET Server Applications: Memory Management

I'll get this out of the way from the start. This series of blogs will have nothing to do with ASP.NET or web services. However, if you plan on writing you own implementation of IIS in managed code this would probably be a good place to start. :) I also won't be providing very many code examples, as I'd be flogged by our intellectual property lawyers. You will not be able to copy and paste and create your own scalable server. However, I hope to provide enough insight so you can avoid a big list of gotchas we have had to figure out the hard way. This is one piece of a huge puzzle, memory management. Yes, you do have to think about that in .NET, at least if you want to build a large scale application.

For those who don't already know, SoapBox Server is a part of our SoapBox Collaboration Platform that supports the XMPP protocol as well most of the interesting JEP extensions. At the core of SoapBox Server is a highly efficient Socket server and thread machine capable of scaling into the hundreds of thousands of simultaneous users, and it's built 100% on .NET (C# now, but used to be VB).

SoapBox Server is the first multithreaded Socket based server application I've had the pleasure of working on. During the course of building the SoapBox Server into the extremely scalable and reliable system it is today I've learned a few things (as has the rest of the team, I hope). Thanks to Chris (who already had tons of experience with such things in Win32/C++), a few bloggers out there, some books, customers finding very interesting bugs, Windbg with Son of Strike, oh and Starbucks, I'd say I'm pretty well versed in the land of building scalable server applications. I'm no Jeff Richter, mind you, but I feel I have now learned enough to at least speak intelligently about it.

In that spirit I'd like to share the fruits of our tuning and debugging work, which, if history repeats itself, will continue to evolve as we begin work on our next major revision of the product. First, I'd like to repeat something I said a couple paragraphs ago, SoapBox now scales to hundreds of thousands of simultaneous connections with a single piece of server hardware. Think about that for a second. A user brings up an IM client, connects to SoapBox Server, and then holds that connection open until they Log Out. Repeat hundreds of thousands of times. This is no simple task. The .NET CLR does not provide a magic "Process.Scalable = true" property. We have invested hundreds of hours into tuning (maybe thousands) over the life of the server on classes of hardware varying from single processor laptops to 16-way Itanium2 systems with 64GB RAM. We've been through four distinct processing models as well as quite a few iterative improvements on our Socket interaction layer. Basically we have ran the server under a bunch of different profilers under many scenarios, found slow bits of code, and fixed them. But I'm not going to talk about profiling and performance tuning; perhaps another time. I'm going to talk about memory and scalable applications.

Every time your application creates a new Socket, Windows pulls memory from it's Nonpaged Kernel memory, which is simply physical memory that is reserved by the kernel and will never be paged out to disk. This block of memory has a finite limit and the kernel picks the limit based on the amount of phsyical RAM available to it. I don't know the exact algorithm, but with 4GB RAM it's usually somewhere around 150,000 TCP Socket connections, give or take. Want to see this in action? Simply create a loop that instantiates sockets. It will stop working eventually with a SocketException telling you there isn't enough buffer space. On top of this hard kernel level limitation, you also have to worry about how much memory each concurrent connection uses in your own application. In SoapBox we store a lot of information about each connection in memory in order to improve performance and decrease our IO operations. This includes things like the user's contact list, their last presence (available, away, busy, etc), authorization information, culture information, user directory information, etc. If we didn't hold this in memory we'd have to hit a file, database, or some other out of process persistent store for the information every time we needed it. Being IO bound is no fun. Believe me, we started out that way.

However, because of our extensive caching, SoapBox Server 2005 can only reliably handle about 20,000 simultaneous connections on the beefiest of 32 bit hardware (on 64 bit it's much, much, much higher -- I also have to admit we haven't stress tested the 2007 build on 32 bit hardware, it would probably be much higher now). It doesn't matter if you have 64GB RAM and 16 32bit processors, it we can still only handle 20,000 connections. Why, you ask? Well, it's because of the 2GB (well, really 3GB with a boot.ini switch) virtual memory limit per process in 32bit Windows. Without delving into managing your own memory your process is only allowed up to 3GB to play with. Typically, we use that up, or rather, .NET thinks we use it up, somewhere between 20,000 and 30,000 connections. Now why would I say ".NET thinks we use it up?" Story time!

A little over a year ago one of our customers kept running into a very bad situation. As evidenced by the Event Log, SoapBox Server was crashing (insert shock and awe here). It was an irregular occurance, but it did happen. However, we did no take this lightly. This customer was running about 2,500 simultaneous connections on a Dual Xeon with Hyperthreading and 4GB ram and the /3GB switch set. It was plenty of hardware for the job, and probably overkill. However, the service was still crashing. We set them up with the Debugging Tools For Windows and had them startup the process to wait for a crash (another blog we'll have to write some day). After a few tries we got a dump with some useful information in it. The result? We were out of memory, sort of.

In .NET when you call any socket operation and pass it a buffer, whether it be a send or receive, synchronous or asyncronous, it takes that buffer and pins it before giving it to the Winsock API's. Pinning, in a nutshell, is taking a .NET data structure and telling the .NET CLR memory manager not to move it, until it is explicitly un-pinned. The memory manager in the CLR is smart. As you allocate and deallocate memory it is constantly defragmenting it for you so the overall memory footprint is lower. There are quite a few really good/long/complicated articles on how this works so I won't bore you. However, pinning throws a wrench in this and the memory manager isn't quite smart enough to deal with it well (though it has gotten a lot better in 2.0). Basically, that buffer you want to put on the socket cannot move in memory (physically -- in terms of you virtual memory space) from the time the socket IO operation begins until it ends. If you look at the Winsock2 API's this is obvious, since the buffer is passed as a pointer. Anybody who's built this type of application in Winsock2 is probably saying "DUH!". I'd consider this a very leaky abstraction. Due to this behavior, it is quite easy to write a socket application in .NET that runs out of memory.

Back to the story! Not only were we out of memory, but the there was only about 200MB worth of data structures in the heap. For those of you like me that use calc.exe for all your basic math let me figure that out for you, 200MB > 3GB. Uhh, say what? How the heck were we out of memory? Well, we ran into the shortfall of pinning and memory fragmentation. The cause of this was a small number of small pinned buffers, in our case 2KB each, that were high enough in the heap to cause fragmentation spanning over 2.8GB. Where did the other 2.8GB go, you ask? Well, is was there, allocated by our process, but not being used by our code. In Son Of Strike (SoS -- a command line plug-in to the Windbg debugging tool I hope you never have to use) this showed up as free, empty, unused space! It was just sitting there waiting to be used, but we still ran out of memory. I think I mentioned earlier the memory manager in .NET isn't so smart when it comes to fragmented memory and pinning, well, this is what happens in the worst case.

Good thing for you, the answer to all your memory fragmentation and pinning woes is quite simple. Pre-allocate buffers for use by anything that will be causing pinning, and do it early on before there is a lot of memory thrash (when your application is rapidly allocating and deallocating a lot of memory). We created a simple class called a BufferPool that we use to pre-allocate a certain number of buffers. This pool can grow as need be, but it does so in large chunks and forces a garbage collection each time before the buffers are actually used. This considerably reduces the chances of fragmentation caused by pinned memory. If the pool starts off with 500 buffers, but then the 501st buffer is needed it will grow by a configurable value, typically another 500 buffers, and the induced garbage collection will cause these buffers to shift to the lowest possible point on the heap.

Interestingly enough when we found this bug we already knew about the pinning behavior of socket operations, but had only solved half of it. All of our BeginReceive calls were using the BufferPool because we knew the buffers would remain pinned until we received data from a client, but the BeginSend calls were not using the pool. We had not even considered the fact that sending a few KB of data might take long enough to pin memory, fragment the heap, and cause an OutOfMemoryException. But there is one case where they do, timeouts. The Windows TCP subsystem is very forgiving. If a client loses its connection and the server isn't explicitly told about it, the next piece of data you try to send to that client socket will end up being pinned while the TCP subsystem waits for the client to respond. It can take up to 5 minutes with the default configuration of Windows for the TCP subsystem to figure out the client isn't really there. During that entire time your buffer is pinned in memory. *poof* OutOfMemoryException.

Unfortunately, pre-allocating buffers does not completely fix the issue of running out of memory. There are also some other limits to the size of a .NET process's virtual memory space that are very complicated and I won't talk about, but basically you end up with anywhere from 1/2 to 2/3 usable virtual memory without running the risk of OutOfMemoryException. So, if you have 2GB virtual memory available (standard on a 32bit machine), you end up with about 1.3GB you can actually use reliably. Of course, this varies, and some applications will be able to use more, or maybe less. Your mileage may vary.

Don't fret, all of the issues I've talked about in here have been fixed since SoapBox Server 2005 SR1. And with the most common usage patterns people were not actually affected to begin with.

I hope this was at least marginally interesting to someone. :) Next up, I'll probably talk about limitations we discovered in the Windows Socket infrastructure, or maybe async IO, IOCP, and worker threadpools, or maybe how in the world we actually test at this scale. Only time will tell, unless Chris beats me to it.

30Apr/100

Coversant® Upgrades Technical Forums

As part of Coversant® continued commitment to customers, we at Coversant® have upgraded our technical and product support forums. Now integrated into our corperate website, the new forums will be moderated by Coversant® support staff with support from our software engineers. Check it out for yourself by clicking on the forum link on the right hand side or going forums.coversant.com.

Each month we will highlight a forum question and solution on our blog site in an effort to educate you, our customers. Please leave us comment and let us know what topics interest you.

If you have any questions about joining or using our forums please visit forums.coversant.com or contact a support engineer at support@coversant.com