473,549 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Optimizing application performance

Airslash
221 New Member
Hello,

not really sure if this is the correct place to ask this, but here goes:

I'm currently working on an application that uses the client-server model to accomplish the following:

- The server grabs images from camera's and stores them on disk.
- The server application talks to the grabber software and obtains the absolute path to the bitmap files.
- The client asks the server application for an image and gets it in jpeg.

The idea behind this is to simulate a videostream by delivering the images in sequence fast enough. Currently I'm encountering the following issues:

- FPS is only 2, I think i'm loosing alot of overhead in the TCP traffic.
- Server goes up to 100% load. My believe is that the altering of bitmap -> jpeg sucks up all available resources.

I'm basicly looking for some guides or information about image processing and client-server architecture. The application is written in C# and relies in .NET 4.0.
I can provide the test application or parts of the code.

Expand|Select|Wrap|Line Numbers
  1.             // Cast the data we recieved to a string.
  2.             string message = Encoding.ASCII.GetString(data);
  3.  
  4.             // Check if we have an @CAMNR message
  5.             if (message.Contains("@CAMNR:"))
  6.             {
  7.                 Invoke(new MethodInvoker(delegate { m_debug.Items.Add("message recieved : " + message); }));
  8.  
  9.                 // Strip the last symbol and the @CAMNR: part.
  10.                 message = message.Substring(7, (message.Length - 1) - "@CAMNR:".Length);
  11.  
  12.                 WriteMessage("stripped message : " + message);
  13.  
  14.                     // Load the image.
  15.                 Image img = Image.FromFile(message);
  16.  
  17.                 // Load the image into a memorystream.
  18.                 MemoryStream fullstream = new MemoryStream();
  19.                 MemoryStream image_stream = new MemoryStream();
  20.  
  21.                 // Load the image into the image_stream buffer.
  22.                 img.Save(image_stream, System.Drawing.Imaging.ImageFormat.Jpeg);
  23.  
  24.                 // Create the byte arrays that represent the header tag and the size.
  25.                 byte[] header = Encoding.ASCII.GetBytes("@IMG:");
  26.                 byte[] size = BitConverter.GetBytes(((int)image_stream.Length));    // Assume ints, since we only need 4 bytes.
  27.  
  28.                 //DEBUG
  29.                 WriteMessage("File size according FileInfo class: " + new FileInfo(message).Length.ToString() + " bytes.");
  30.                 WriteMessage("File size according Array Length: " + image_stream.Length.ToString() + " bytes");
  31.                 WriteMessage("File size as int representation : " + ((int)image_stream.Length).ToString() + " bytes");
  32.  
  33.                 // Append the data to the memorystream.
  34.                 fullstream.Write(header, 0, header.Length);
  35.                 fullstream.Write(size, 0, size.Length);
  36.                 fullstream.Write(image_stream.ToArray(), 0, image_stream.ToArray().Length);
  37.  
  38.                 WriteMessage("Image loaded into the memorystream.");
  39.  
  40.                 // Convert the entire memorystream into an byte array.
  41.                 byte[] buffer = fullstream.ToArray();
  42.  
  43.                 // Start pumping out the data over the network socket. This will be done in several bursts depending
  44.                 // on the settings of the network.
  45.                 m_client.GetStream().Write(buffer, 0, buffer.Length);
  46.  
  47.                 WriteMessage("Image send to client.");
  48.             }
  49.  
This is the code that I use to respond on a image request. It loads the bitmap, turns it into a jpeg and delivers it to the client. My guess is, that the biggers overhead problem exists here already, but this sort of uncharted teritory for me.
Aug 10 '10 #1
12 1489
Oralloy
988 Recognized Expert Contributor
Well, if the server load is 100%, I can almost guarantee that your 2FPS is not due to TCP/IP overhead.

There are a couple things you can do
1) You can pre-convert the bitmaps to jpeg images
2) You can send unconverted bitmaps

Otherwise, you should just buy an off-the-shelf package and have done with.

Good Luck!
Aug 10 '10 #2
Joseph Martell
198 Recognized Expert New Member
When it comes to optimization one of the ideas that I see coming up all the time is to make sure you are solving the right problem.

One of the first things that I would do is create a basic logging class that can be used to log how long specific portions of your program take. Right now you are guessing that the TCP/IP overhead and image conversion is what is killing your FPS, but that is just a guess. Your program also has file i/o, which can be slow, and it is executing a bunch of framework code behind the scenes. You may be surprised what is eating your processing time.

All of these are guesses until you do some diagnostics to find out where your time is actually being spent. I wouldn't want to optimize my image conversion code to death only to find out that I had a .Net Framework TCP/IP setting that caused poor performance.
Aug 10 '10 #3
Airslash
221 New Member
In all my quickness & sillyness I forgot to add Thread.Sleep calls in certain functions for what a Thread has nothing to do....

Now the CPU load has been reduced to 0 :)
Only other problem I have now, is that the sleeping threads mess up my TCP communication, because they don't respond fast enough.

Guess I'll have to change a bit in the protocol and make it more event driven instead of linear messages.
Aug 10 '10 #4
Oralloy
988 Recognized Expert Contributor
I still find it quite difficult to believe that the TCP/IP throughput is affecting your frame rate.

Well, I can imagine how, but you'd have to be using a slow-speed connection like 9600 baud SLIP. Either that, or your network is so loaded that you really are suffering throughput problems, in which case you'd have noticed the problem long before this.

Give your event driven model a try and let us know how it works out.

Cheers!
Aug 10 '10 #5
Airslash
221 New Member
I've written a new class that handles everything through timers, and i still couldn't get above 10FPS, while theoritcly i should hit 60FPS.

After searching a bit, it seems my applications always needs to wait 100ms to recieve an UDP reply from a third application that tells where the image is located.
So I can never breach the 10FPS barrier as long as the third application doesn't speed up.
Aug 18 '10 #6
Joseph Martell
198 Recognized Expert New Member
Sounds like you'll either need to settle for 10fps or buffer your images.
Aug 18 '10 #7
Airslash
221 New Member
Probably,
but I'm defo poking the devs of the third application.
Waiting 100ms on loopback for an UDP reply is not acceptable.
Aug 18 '10 #8
Oralloy
988 Recognized Expert Contributor
Can you turn down that 100ms, or is that just the inherent response time of the third application, and something you can't affect?
Aug 18 '10 #9
Airslash
221 New Member
it's the response time of the application, and would require a serious overhaul I think it make it faster.

It's build on 10year old legacy code and constantly beeing added to;....
So to adjust something in there is like playing with matches in a TNT factory...
Aug 18 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1724
by: Steve_CA | last post by:
Hello all, I've been recruited to assist in diagnosing and fixing a performance problem on an application we have running on SQL Server 7. The application itself is third party software, so we can't get at the source code. It's a Client Management system, where consultants all over the country track their client meetings, results, action...
3
3111
by: Amit Dedhia | last post by:
Hi I am developing a Dot net application (involving image processing) on a uni processor. It works well on my machine. I then take all my code on a multi processor, build and run the application there. There is performance degradation. The usual performance of the application on MP machine is better than that of uni processor machine....
0
1110
by: Girish NS | last post by:
Hi, I'm developing a MDI application. I'm facing problems with the performance of the MDI child forms in the application. The load time of child forms is very slow. In case of MDI child forms having background image and handling paint event, the load time is even slower due to the background painting. Repainting of form controls is also...
5
1460
by: Anders Both | last post by:
Does someone knows links to web-pages, or book contatining, information about the most important things to consider, while trying to make the .NET code perform faster. e.g. In my code I make big use of ArrayList and Hashtable, but my code would be only a little bit more complicated, if using normal Arrays. I feel like a thing like that...
1
3286
by: Dominic | last post by:
Hi all, We've just migrated to IIS 6.0 / Windows Server 2003. We are now experiencing some stability problem what we did not experience in IIS 5.0 / Windows 2000 Server. Our ASP.NET application is running in a web-farm environment of multiple web servers. We have been using "Performance Monitor" to monitor the "Requests in Application...
3
2586
by: groups | last post by:
Hi all, I've recently ported a rather large C application to run multithreaded. A few functions have seriously deteriorated in performance, in particular when accessing a rather large global array, that contains information that is shared among threads. Any idea, why the lines accessing this global array now take about 50x longer in the...
2
1133
by: Yoav Shtainman | last post by:
I combined several application projects into one large project for ease of management and control. My previous application was a collection of small independent projects. Can this change affect the performance of the application? It is a .NET Web application using SQL Server back end
8
1865
by: NAdir | last post by:
Hi, thank you for your help. My VB.Net application contains a document that the user can refresh at any time. The refresh works fine and needs to loop through few datatables (hundreds of rows). This works fine until I delete some rows in two tables. Just after the delete if I do the refresh there is a huge memory allocated and the time...
4
1507
by: skotapal | last post by:
Hello I manage a web based VB .net application. This application has 3 components: 1. Webapp (this calls the executibles) 2. database 3. business logic is contained in individual exe application that get called in a sequence to do some heavy calculations (mainly DB operations with in memory datasets)
1
1512
by: mjheitland | last post by:
Hello, does anyone know if an update is available (or at least planned) for the much cited standard reference IMPROVING .NET APPLICATION PERFORMANCE AND SCALABILITY? link: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag/html/scalenet.asp or as a download:
0
7461
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7730
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7823
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6055
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5101
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1068
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.