473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Optimizing application performance

Airslash
221 100+
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 1484
Oralloy
988 Expert 512MB
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 Expert 128KB
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 100+
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 Expert 512MB
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 100+
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 Expert 128KB
Sounds like you'll either need to settle for 10fps or buffer your images.
Aug 18 '10 #7
Airslash
221 100+
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 Expert 512MB
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 100+
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
Oralloy
988 Expert 512MB
Awwww, you're no fun any more....

:)

Good Luck and A Great Day!
Aug 18 '10 #11
Airslash
221 100+
guess that's what happens when you have to deal with legacy code....:P

Now I just need to make the other's accept the problem is theirs and not mine :S
Aug 18 '10 #12
Oralloy
988 Expert 512MB
Well, ask them if they want the 60 frames/sec.

If they do, then they need to provide reasonable resources to resolve the legacy system performance/delay issue. And, they should be aware of the possibility that a timing tweak can far exceed the work necessary to change a simple delay timer, and be prepared to pay for it.

Good luck!
Aug 18 '10 #13

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

Similar topics

5
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...
3
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...
0
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...
5
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...
1
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...
3
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...
2
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...
8
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)....
4
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...
1
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:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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,...

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.