> > Frans Bouma wrote: > > > Consider an object which is serializable to XML using the SOAP > > > formatter. the XmlSerializer is first serializing the object to XML. > > > > This is done using an utterly slow, FILE based approach. > > > > Where does this persistent myth spring from? > > because it is true? Does it or doesn't it use the file system to > create sourcecode it has to compile? You said it yourself:
Ah but as Ian says it only gets invoked the first time a type is serialized. Now assuming we are talking server side software (because this whole discussion is pretty moot otherwise) then it is hardly a likely usage scenario that we only ever try to serialize a type once or twice. In any high volume set up the cost of upfront compilation is massively ameliorated over the lifetime of the number of calls. Otherwise people would say "hey, that ASP.NET is rubbish it compiles your code - its performance sucks big time" which is true if you only ever hit a page once. > > > It's true that the first time you fire up an XmlSerializer in > > a process, there's some disk activity. But only the first > > time. If you observe what's going on with FILEMON, you'll > > see that the first time you ask for an XmlSerializer for a > > particular type, the C# compiler gets fired up. > > > > But once you've asked for the XmlSerializer for that type, > > you can ask for it as many times again as you like, and it > > you'll not see any disk activity at all - it just reuses what > > it built earlier. (And if you care about performance, > > presumably you were planning to serialize and/or deserialize > > more than just once, right?) Nor will you see any disk > > activity when you ask it to serialize and deserialize objects > > for you. (Unless you serialize via FileStreams of course...) > > ... I just said the XmlSerializer uses the filesystem which IS > slow. That's all I said. You shouldn't read more into things I didn't > say in the first place, Ian. > This is very disingenuous. "Hey I only said it was slow in this one instance I quote - don't start throwing real world situations at me". > > So there's nothing intrinsically file-bound about > > XmlSerializer once its up and running as far as I can tell. > > I'm pretty sure it will then run the types it has created to > produce the xml for a given type, code which is not unloadable from the > appdomain btw. > Yes, but if you are repeatedly using the code who cares whether it's unloadable or not - I don't want it unloaded. I'm not saying that its great that its not unloadable, just that its not pertinent to this discussion. > > And aside from that one detail, what about your more general > > claim that XmlSerializer is slower than SoapFormatter? > > SoapFormatter is pretty slow also, but it's my experience that > if I serialize a type to disk using soapformatter or using xmlserializer > the soapformatter is faster big time. IF the xmlserializer is even > capable of producing XML because it bites the dust as soon as it runs > into an interface typed member variable, something the soapformatter can > handle nicely and which has always got me wondered why on earth the > xmlserializer wasn't capable of producing xml with interface types or > cyclic references. > Well now we get down to the crucial issue of this discussion - its all a question of type. As I'm sure you know, the only thing the SoapFormatter has in common with web services is that it has the letters S.O.A. and P in its name. It emits a bizarre serialization based on Rpc-Encoding (Soap section 5 type transition rules) plus some stuff that assumes .NET on the other end of the conversation. The Asmx stack doesn't use the SoapFormatter - it uses the XmlSerializer directly. Web Services are designed to be cross platform so we can't assume a particular type system - therefore we use a portable one - Xml Schema. This is the reason cyclic refs and interface types can't be handled by the XmlSerializer because it is schema driven and Xml Schema doesn't support those. So if you want to make an argument in defence of Soap Section 5 encoding that’s fine but for webservices we take an XSD view of the world - which is not object based. Now I know this is part of the argument about web services not being suitable for some jobs and yes you're right - but we need to take a view on why some restrictions are there rather than say its broken because it down't support x or y. > > There's a fairly well-known article on MSDN that talks about > > the relative performance of various styles of .NET remoting > > vs .asmx web services: > > > > http://msdn.microsoft.com/library/en-us/dnbda/html/bdadotnetarch14.asp > > > > Notice that the throughput and response time of SOAP over > > remoting is substantially *worse* than .asmx for all user > > loads when hosting in IIS. > > Who hosts remoting services in IIS? Of course it's slower in > IIS. :) This is about communication between 2 applications on a binary > level. Why would you need a webserver/http consumer/xml serialization > etc. etc. ? You just want to get the binary stream across. So what do you do about security (assuming you aren't going to base your application architecture on unsupported sample code)? I'm not saying that there aren't situations where a distributed app is running in a trusted closed environment - but there are a large number of situations where this is not the case and for these IIS hosting gives a reasonable approach - especially that once you go this route you get a whole bunch of goodness with scalability that the TcpChannel denies you by trying to hang on to its connections. But of course - once you have ASP.NET hosting why not use web services - ah complex object graphs - lets move on > > > This is further reason to be suspicious of your claim that > XmlSerializer is slower than > > the SOAP binary formatter. Apparently XmlSerializer is > > faster here. The only situation in which the SOAP binary > > formatter can do better (and even then, only some of the > > time) is if you use the TCP channel and don't host in IIS. > > And yes, those two things are have performance benefits, but > > again it has precisely nothing to do with the XmlSerializer. > > (In other words, SoapFormatter only looks better if you stack > > the odds in its favour first.) > > Again, Ian, I just said it was slower, I didn't mention a > situation nor a context. If I have to serialize a big object graph to > disk using teh soap formatter it's 'faster' (it's pretty slow) than the > xmlserializer. I'm not serializing the graph to disk every 20 seconds, > just now and then. Why should I then conclude "the xmlserializer is > faster", because it isn't? In other situations it is perhaps, due to the > code it generates which hardcoded produces xml for a given type... Passing complex object graphs is a thorny problem for distributed systems, even if we do have the same type system on both ends. We need knowledge of every type in that graph on both ends of the wire - even if they are interface based (interfaces are still types). All concrete types must be either serializable or inherit from MarshalByRefObject. We better hope the former or we have network roundtrips to talk to the objects. There are few situations where I have found it necessary to pass massive amounts of state on method calls - which is where object graphs come in useful. But assuming we are doing something meaningful with the data - like writing to a database, etc - then passing an XML stream is going to be ameliorated by the number of database roundtrips - especially if you process it using the streaming XML API (XmlReader and friends) rather than load it into the DOM. > > Nevertheless, the XmlSerializer is unnecessary in a webservice > setup if the client of the service isn't consuming XML. However you > can't exclude the XmlSerializer in a webservice, which can be very big > problem if you have complex typed member variables or interface typed > member variables in the objects in the graph: the xmlserializer can't > handle these. What to do then? Implement IXmlSerializable? No can do > either, as the XmlSerializer then thinks the complex type is a dataset. > > Not only is XmlSerializer unnecessary, it's also a big pain for > that reason, and all that for producing XML which is not consumed as XML > anyway. Now it may be worth moving away from the through of XML as angled brackets, etc and think in terms of its abstracted model - the Infoset. Because XML is a model is a very powerful and extensible way of expressing information - if only that damn wire format were smaller. I agree that there are issues with passing large blocks of XML over the wire and that the binary rep is almost certainly smaller. This doesn't mean that this will always be the case (well actually it will always be the case to a degree - a tuned binary rep will be smaller than a binary rep with structural info in it too - just not by loads). > > > Only two of the possible remoting configurations consistently > > outperform the .asmx web service implementation according to > > those tests. They are the TCP Channel + Binary Formatter, > > and the HTTP Channel + Binary Formatter, both running outside > > of IIS. (And that latter is extremely close. It's only the > > TCP+Binary+not-IIS option that gives you a really substantial > > benefit.) > > ... which is also the only sane option for doing remoting in a > 100% .NET environment, because who needs the XML if it's not being > consumed at the client? That was the whole point! > > > Have you run other tests that contradict these (fairly widely > > reported) tests? Or are you just describing what you think > > should be fastest, based on some internal mental model of > > yours? If there is other evidence around that tells a > > different story, then again, I'd love to see it. > > I was describing the result of a setup where I ran into this > issue with the code being generated in the background which severily > stalled the process. You now wrote a long rant telling me I was wrong > and I apparently stepped on your towes and for that I'm sorry. You > totally missed the point though. The point was that because webservices > use xml which is totally unnessecary, the XmlSerializer is used no > matter what, while you don't need xml to get services to talk to clients > and vice versa! :) > > > > However if you just have an application sitting on 2 1U > > boxes in the > > > same 19" rack, why on earth would you set up the > > communication between > > > the processes on both boxes via xml? > > > > There's a very good reason not to use .NET remoting in such a > > setup. (That's not an argument in favour of XML per se, of > > course. However, web services don't suffer from the problem > > in question.) .NET remoting requires both ends to share type > > information. This entails a degree of coupling between your > > systems that is likely to be highly undesirable. > > Everybody who has written a remoting setup knows that this is > easily circumvented by defining an assembly with just interface > definitions which are implemented by teh server and consumed by the > client. You don't need to store type implementations on server and > client, just the interfaces. > > Why is it highly undesireable that systems are coupled? > Webservices are also coupled. these types are also known at the client!! > In fact, VS.NET regenerates classes for those types at the server when > you add a web reference, but these regenerated classes can often be a > big pain as they don't contain deeper logic and will cause casting > errors along the way (so you have to alter these generated classes by > hand). > > A service which provides an interface should have a well known > interface, which implies that the interface is known on the client. > Otherwise the client can't consume the service... > > > There's also a good reason to host in IIS today, which is > > that it's the only supported mechanism for getting integrated > > authentication. You can use that on both .NET remoting and > > .asmx of course, but remember that once you host in IIS, > > you've already lost the lion's share of the performance > > advantage .NET remoting could otherwise have given you. > > Integrated authentication can be 'good' at first, but once you > use a remoted service, you should protect the datastream anyway, which > doesn't make non-IIS remoting a bad solution per se. If 2 applications > just have to communicate on a binary level, why on earth do we need this > big stack of overhead services to get that going? :) I'm not saying > everybody should now start writing his own socket consuming > communication library, however there are far more efficient ways of > getting data accross and calls accross than a full stack inside a > webserver with an HTTP consumer/xml producer etc. > > > It's true that if you use the binary formatter and TCP > > channel, .NET remoting can offer better performance, > > especially if you are able to host outside of IIS. But it's > > not as big a difference as some make out. Moreover, you are > > increasing the coupling in your system, so you really have to > > ask yourself whether that last ounce of performance is more > > important to you. > > Could you please provide some argumentation why the close > binding of a server interface with the client is so bad? If you > implement an interface on the server, the client should be able to > consume that interface and know that interface, be it a remoting server > or a webservice. The server then can later on implement another > interface for other clients, or upgraded clients. Bad design? I don't > think so. > > Talking about myths, I think the fear for having coupled systems > is based on a big myth. If coupling of systems is so bad, every tier in > an n-tier system should be completely abstract and only be communicating > with others through xml (both commands and data). The vast majority of > systems have coupled tiers or better: tied bindings between service and > consumer, be it in an n-tier system, remoting or webservices. This is by > design, and not bad at all. > > > Sometimes it is. But you seem to be saying that web services > > are always the wrong choice, and I really can't agree with that. > > As long as XmlSerializer is REQUIRED, webservices are the wrong > choice, especially in situations where you are communicating between > 100% .NET applications. That was the start of the argument btw: > webservices vs. COM+ with its dcom. They are ONLY the right choice if > the clients are not .NET, and/or when pure XML in a given format has to > be consumed/produced. I'm not very sure if that's the majority of > systems currently being developed with webservices. > > The XmlSerializer is severily broken as it can't produce Xml for > simple classes with interface typed members, it can't handle cyclic > references, it can't handle correctly classes which implement > IXmlSerializable (to work around these issues). I'd love to implement > IXmlSerializable to connect its methods to my ReadXml and WriteXml > methods which do serialize cyclic references and interface based types > to xml in my classes but I can't, due to the hardcoded paths in > XmlSerializer for that particular interface. The IXmlSerializable issue is fixed in Whidbey IIRC > > Aren't you agreeing with me that if you have two boxes, A and B, > and on both an application is running and communicating with the other > one on a binary level, that it is completely insane to run this > communication through a webserver/http client, xml > serializer/deserializer, soap envelopes etc. ? :) Do you really see the > need for that full stack? I don't. In the early days we used sockets on > Unix and RPC. That's very low level and I fully agree a bit more > sophisticated layer on top of that might be very handy. However a full > stack of services on top of eachother producing XML in the end is nuts > as all the work done in that stack is not used, the XML is not consumed > as XML, it's just a different format the data is in, but it was already > in a format. That was the original point of the argument started: xml is > not needed in that situation, so leave it out of it, no matter how much > code is generated behind the scenes to produce xml on teh fly. > > FB > Well if you want to boxes to talk to eachother and massive scalability isn't an issue and neither is security then yes - remoting is exactly the right solution. It depends on what sort of app you write. Now back to the original point about web services and COM+. Indigo is "meant" to add distributed Tx and the rest of the WSA stuff so that we have a whole bunch of services available to code if we want them. We then know that when we write stuff its not going to be redundant if we change or implementation to another technology. Also multiple endpoints can implement the same service in different technologies. No one is bound to anything (other than the web service specs). Now I agree that the state of web services is in its infancy at the moment and I would make a bet that a binary XML wire rep starts coming through in the next few years. As you have argued, the issue is now and no - there isn't a solution that is not based on web service technology on Microsoft's agenda in the long term. One would hope that not all machine to machine communication will be text based XML in Indigo - but we'll have to wait and see. Regards Richard Blewett DevelopMentor > =================================== > This list is hosted by DevelopMentor. http://www.develop.com > Some .NET courses you may be interested in: > > NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles > http://www.develop.com/courses/gaspdotnetls > > View archives and manage your subscription(s) at > http://discuss.develop.com > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.577 / Virus Database: 366 - Release Date: 03/02/2004 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.577 / Virus Database: 366 - Release Date: 03/02/2004 =================================== This list is hosted by DevelopMentor® http://www.develop.com Some .NET courses you may be interested in: NEW! Guerrilla ASP.NET, 26 Jan 2004, in Los Angeles http://www.develop.com/courses/gaspdotnetls View archives and manage your subscription(s) at http://discuss.develop.com
