|
Hi...
When I try to Deserialize a stream of data to an object, it throws an exception "no top object". Any help?
Its not reproducible always.
The code(relevant portion) goes like this:
public virtual ObjectGraph DeSerialize(MemoryStream memoryStream)
{
BinaryFormatter formatter = new BinaryFormatter();
try
{
memoryStream.Seek(0, SeekOrigin.Begin); ObjectGraph objectGraph = (ObjectGraph) formatter.Deserialize(memoryStream);
return objectGraph;
}
catch
{
throw;
}
Any help will b greatful..
Thx in advance..
Ganesh.
|
|
|
|
|
Hi,
I am interested in comments / experience people have wrt writing a tcp server in .net.
We currently have existing an existing server, written in native c++. It communicates with our own browser client using a proprietery protocol and services hundreds / thousands of concurrent connections. The server uses blocking sockets in multiple threads to obtain reasonable performance.
We are investigating a to move from native code to .net code.
I am not sure which language, but at this stage c# or managed c++ seem to be the best options.
I know that we could do the clients in .net.
However, I am unsure about the suitablility of .net for the server.
In particular wrt cpu usage.
|
|
|
|
|
It very much depends on how you write your code. Algorithmic complexity normally outweighs the exact instructions executed. Given the gap between processor speed and memory speed, you'll normally get better performance by being efficient with memory. While your code may be JIT-compiled,
I note that you're using blocking sockets. If you use a large number of threads which are mostly blocked, you'll end up thrashing the CPU cache and losing cache locality. For a really high-performance server, consider switching to asynchronous I/O.
Using asynchronous I/O in unmanaged C++ can be quite a pain. Using .NET, it's relatively easy: System.Net.Sockets.Socket provides a BeginRead method which will call a callback function on a pooled thread when data is available. This allows the server to use a smaller pool of threads to handle the requests.
It's best to create a number of static buffers for your I/O buffers. That way, they rapidly end up in generation 2 and stay there. You therefore avoid the problems with medium-life objects causing a lot of GC overhead (see Mid-Life Crisis[^]).
At present I'd suggest not using Managed C++. The syntax is changing for VS2005, and while the existing syntax will be supported, it won't be enhanced.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
My understanding is that since the tcp/ip stack runs in kernel mode, threads blocked on a tcp/ip calls do not cause excessive thread management issues (eg thrashing) for the os. I have stress tested our server with over 1 thousand connections, all continousuly sending dummy data on a std P4 1.6 workstation. The test ran for approx 2hrs. The cpu utilisation & memory usage (as reported by the windows taskmanager) did not appear to be excessive.
I can see some benefits from having a single thread poll select() & then off load the work onto a thread from a fixed (or controlled) size thread pool. However I seem to remember hearing of issues with select() when it is called with large no.s of sockets.
In any case, I can move our existing code over the using select(), without too much difficulty. I assume that is what BeginRead does & that it can be used in a non gui app).
However, my main question still is:
"Is .net efficient enough to use as the basis for a concurrent tcp server which must be able to handle many hundreds of concurrent connections."
|
|
|
|
|
When you receive data on a connection where a thread is blocked on the socket, the kernel puts that thread on the runnable list. The kernel tries to balance the demand for CPU resources by switching between threads in a runnable state. At any given time there can only be one thread actually running on each logical CPU. The OS switches to a different thread if the running thread blocks, if the thread's quantum (time permitted to run) expires, or if another thread with a higher priority becomes runnable.
In the design where you have one thread per client, you can get a situation where multiple clients send packets simultaneously, unblocking all the threads for those clients. The OS then ends up switching between them. Context switches are not free - they take time. They also generally cause processor cache misses as each thread refers to data on its stack. A processor cache miss is not reflected in the performance counters, but it does take time.
This is time that could have been spent servicing requests.
Windows also offers asynchronous I/O. With asynchronous I/O, threads can be performing useful operations while the I/Os are pending. If the socket is not associated with a completion port[^], the I/O is associated with a particular thread.
I/O completion ports allow I/O to be associated with a pool of threads, so that any thread blocked on the completion port can handle a completed I/O. Windows performs some special tricks with threads associated with a completion port:- Threads are released from the completion port in reverse order of blocking - that is, the last thread to block is the first thread released. This helps prevent cache thrashing.
- Windows only releases as many threads as can be handled with the CPUs in the system (or as many as specified, if the number of concurrent threads is specified when the completion port is created).
- When a thread blocks on some other operation, Windows releases another thread from the pool waiting on the completion port, if there is one and there is work for it to do
In this way, Windows keeps all the CPUs busy.
The Framework does all the work behind the scenes to associate asynchronous I/O operations with a pool of worker threads, and manages the thread pool for you. You don't have to consider whether an asynchronous I/O completed synchronously (this can happen) as the Framework calls your callback function in either case.
This is rather different from select , which is a polling function. A transition from user to kernel mode is required for select to determine whether any data is waiting. It also has the problem that you can only specify a given maximum number of sockets in an fd_set (by defining the FD_SETSIZE macro).
Microsoft implements many of its network servers in this fashion - including IIS before version 6.0 (version 6.0 introduces the HTTP.SYS driver which performs much of the HTTP protocol in kernel mode to save kernel->user transitions).
Given the scale of your testing, you might not see much difference. I recently implemented a UDP-based client emulator in C#, using BeginSend/BeginReceive, to test against our application server. I found that it was using 20 threads to emulate 1000 clients with no think time. The server software, written in VB6 and mostly single-threaded, was unable to keep up with that rate of requests.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
thanks for the comments, they have been quite informative.
I understand how thread management works & the overheads associated. My understanding is that having a thread blocked by a kernel object (eg mutex) reduces the thread management overhead for that thread. As the tcpip stack is in kernel mode, i have assumed that blocking on a winsock call is like blocking on a mutex wait.
In any case, io completion ports seem to offer better performance, at the cost of using windows specific code. In fact I had just started reading about ioscp & I intend to investigate them further. Any one know of any good code examples (unmanaged &/or .net)
I assume that BeginRead uses iocps
Wrt our existing server, it uses 1 thread per socket connection. My tests involved running client emulators on 10 pcs, each emulating 100 clients, each client repeatedly sending data to the server. The PCs were connected in a 100Mbs lan.
Wrt .net & iocps.
Can .net code that uses iocps (ie BeginRead) be ported to unix via mono?
|
|
|
|
|
kon_t wrote:
Can .net code that uses iocps (ie BeginRead) be ported to unix via mono?
Yes. Managed C++ can cause problems with Mono if you use the Windows API, but pure C# applications should run on Unix just fine -- not even porting, but just running as-is. There's just small things you need to watch out for; things like keeping the directory seperator ('/' and '\') and endline ('\n', '\r\n') neutral (use Path.DirectorySeparatorChar and Environment.NewLine respectively). Also, Windows.Forms, the GUI component, is not quite complete yet.
.NET uses thread pooling [^] to take care of its asynchronous socket connections: "The .NET Framework uses thread pools for several purposes: asynchronous calls, System.Net socket connections, asynchronous I/O completion, and timers and registered wait operations, among others."
I'm working on a mini-http server in C# right now (uses BeginRead and such), so it might be interesting to try hammering it with connections. I could give you statistics and such if you're interested, sometime in the near future.
|
|
|
|
|
I have recently completed the implementation of a bridging service between a propietary system and SAP. The service receives all of its requests from the propietary system, retrieves the appropiate result from SAP and returns it.
I used asynchronous sockets in C# to do this.
The service handled 1000 simulaneous connections during tests without noticeable delays in response.
On the downside, the memory usage is tremendous. .NET FW + Service = 10 (Idle) to 25 (1000 Conns) MB. And I don't keep any results.
Cheers
Sid
|
|
|
|
|
Hi,
I am a beginner in VB.Net and have written a Custom Control that uploads file to a share point server. The control Runs in the Web Browser. The problem I am facing is that when I print the Html page that contains the Control .. the Control wont get printed instead there is a deformed shape of the control that gets printed. The rest of the contents on the page are printed fine.
I am printing through the Web Browser.
Any help will be appreciated.
Thanks in Advance
Khurram
|
|
|
|
|
Hi Friends,
In my DataSet I have 1 column where in I store date of type Hours (eg.
12:15). I have 5 records in my Dataset. Can I get the sum of hours of all the 5 rows. If yes
how is it possible?
For Eg I have 5 records in my Dataset
Hours
---------
01:30
02:00
01:00
02:30
03:00
I want the summation of hrs for all the 5 records i.e Total Hrs = 10:00. How do I get that?
Regards,
Vipul Mehta.
Regards,
Vipul Mehta
Software Engineer
Chenoa Information & Software Services Pvt Ltd
|
|
|
|
|
as far as I remember you can simply access this data by view or directly from dataset, but you can also try to formulate proper SQL query and you will get what you need
--
Why a sin?
|
|
|
|
|
When I create a ATL project in under C++ projects in VS 7.1 a additional project <project name="">PS is also created. For exmaple if I create a project with the name "Test1" then "Test1PS" is also created. Can anyone let me know why this is create?
Thanks in advance
Sharath
|
|
|
|
|
Test1PS is a project to build a separate Proxy/Stub DLL for marshalling. This DLL is loaded by COM if it needs to marshal calls between different contexts - for example, between different apartments in a single process, between different processes on a single machine, or between different machines.
You can build a separate proxy/stub DLL if you want to deploy it to a different machine, or if you don't want to load your whole DLL into another process. Proxy/stub DLLs are also used if you're building a local server (an .EXE). This is the only supported scenario if using attributes, which is the default in VS.NET 2003. If you don't use attributes you can make the proxy/stub classes part of your component DLL, but you need to define your interfaces using IDL.
A custom proxy/stub DLL is not required if your interface conforms to the Automation standard. In this situation the type library is sufficient. Registering the type library causes keys to be written to the registry which register the Automation marshaller as the proxy/stub for your interfaces.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
hello,
I want my application to send a request to search engine(Yahoo.com ,Excite,Altavista,msn) and the search engine should return the URLs of the top 10 sites that match the keywords I sent to the search engine.
I have found google.com contain an API for developers but the other search engines does not provide a similar API or web service.
Thanks in advance
|
|
|
|
|
Hi :
I Want To receive A Raw Packets from My Modem
Then I want to Modify The Content Of The Packet And resend it through my modem using C#.Net
Thanks
B.A
|
|
|
|
|
Hi,
My Solution has 3 Projects placed in 3 directories. 2 projects generate DLLs, 1 project generates the final application using the DLLs (at load-time). When I start debugging, I would like the EXE to always find the last compiled DLLs.
For this I see two ways:
- copy the DLLs after each (re)compilation into the EXE directory.
- include the DLL directories into the PATH environnement variable just before Debugging
I did managed NEITHER NOR, from inside Visual Studio. Can someone HELP me?
Thank you very much,
Jerome
|
|
|
|
|
I need the flow of Microsoft speech server in .NET ,How the web controls are embeded with the the SALT and how the text is retrieved from voice if the frequency varies from user to user for the same context.Please reply to this to my personnal id anand.asv@gmail.com
thankyou....
regards,
Anand
|
|
|
|
|
Hello all...
I have created a simple windows service that monitors some folders using a FileSystemWatcher and moves any files saved to these folders. I have built a windows forms application that displays the status of the service and allows the user to stop and start the service. What I would like to do is have this application respond to events raised by the libraries used in the windows service, so I could display status and error messages. I am not exactly sure what would be the appropriate method to implement this. From what I can find, it looks like perhaps I should use .net remoting to communicate between the service and the client.
Can anyone help point me in the right direction?
Thanks in advance for your help!
Oblio Joe
|
|
|
|
|
Add a tab control to a resizable form, set the tab control docking to full... resizing the form causes the tab control and controls in it to flicker like crazy. Seems to happen at least when using C# or C++.
Is there any way to stop this problem? Thanks.
|
|
|
|
|
Is there any available design patterns that allow you to add data to hash tables in a transactional manner? (ie: roll back the addition in the event that adding data to one should fail)?
I am building a prototype class for a project I am working on that needs to store some data and I am trying it out two ways to see how it works.
One way is to use an in memory dataset with a few columns to store the data, the other on using a few hash tables to store each column along with its key.
Since the addition to the hash tables will require multiple hashtabel_name.Add() function calls I am thinking that there is the remote possibility that one add might fail for some reason. I would love to be able to roll back the other additions that have been made up to the point where I error out. Barring the use of a try/catch block around each .Add() and then the correct .Remove() calls for each of the previous hash tables, is there any 'known and tested' way of doing this?
Am I wasting my time here? Would it just be simpler to use a dataset for this and do my CRUD with SQL queries when I need to? I want to keep this as lean as needed. The data will not need to be persisted to any physical devices (ie: saved to disk) and is only used in the context of the class.
The big reason I am considering the hash table route is that one of the 'columns' needs to store a reference to another class and I am not sure if I could accomplish what I am trying to do with a dataset.
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
Hi, I have to convert a VB.NET application to C#. In the VB code, the expession CInt(True) is used. I read that CInt(True) was equal to -1 while Convert.ToInt32(True) was equal to 1.
Now I'd like to convert CInt(True) to C#... how can I do it? I can't use an explicit cast since we can't convert a bool to an int, and I can't use Convert.ToInt32() ... what can I do???
Thanks!!!
|
|
|
|
|
Not exactly sure what you are trying to do. It really depends on the context of your application. If the value is being persisted (in a file, database, etc.) then you can use an if statement to convert true to -1 in order to keep consistent with old data. But if being used in some sort of a comparison, lets say, then you need to evaluate what it's being compared to and make a decision around that.
BTW, have you looked at any of the available automated VB.NET to C# converters out there? There are some free ones too.
|
|
|
|
|
Why don't you write your own function that does the job?
private int ConvertVBBoolToInt(bool val)
{
return (val ? -1 : 1);
}
|
|
|
|
|
Maybe I am showing some low-level ignorance of data types here but I just don't understand why we have these
VB.NET
Short
Integer
Long
C#
short
int
long
When we have these:
System.Int16
System.Int32
System.Int64
Can anyone explain this to me?
If it is just for backwards compatibility with code on the part of VB I don't really buy it because the same things are there in C# and there should not have been any backwards issues with 'old C# code' to worry about.
Anyone want to enlighten me?
Paul Watson wrote:
"At the end of the day it is what you produce that counts, not how many doctorates you have on the wall."
George Carlin wrote:
"Don't sweat the petty things, and don't pet the sweaty things."
Jörgen Sigvardsson wrote:
If the physicists find a universal theory describing the laws of universe, I'm sure the a**hole constant will be an integral part of that theory.
|
|
|
|
|
I believe that the System ones are objects, and the other ones are basic types, which means among other things that you can't do if myObject is short
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|