none
Performance issue with our application installed in machines with win 2012 r2 server RRS feed

  • Question

  • We have a .NET application that reads the tiff files and displays it in the UI. We recently upgraded our presentation servers from windows server 2008 [not R2] to windows 2012 server r2 and started seeing serious performance issue with our application. We analyzed our code and found the following code execution to be comparatively slow in windows 2012 R2 server compared to windows 2008 server [not ]. We have .net framework 4.6 installed in both the machines.

    Bitmap.Save(byteStream_ImageFormat.Png)
    Bitmap.Save(byteStream_oImgFile.RawFormat)
    Bitmap.SelectActiveFrame(FrameDimension.Page_page)
    new System.Drawing.Bitmap(ImageFormat.Png)
    new System.Drawing.Bitmap(imageFromFile.RawFormat)

    I have attached the sample project as well as sample image along with this post. This project can be run in two different OS and can be used to compare the performance in Windows 2008 server and Windows 2012 server r2. (https://drive.google.com/file/d/1N8JK6lePqrRu_MiqFaYhoR5uwBrGDvU1/view).

    The sample tiff image attached with this project is small but in our real application the tiff images are larger than this. Please find the comparison summary below:

    Our application performs 2-3 times slower in windows 2012 server machine than compared to windows server 2008 machine when dealing with the tiff images.

    Windows Server 2008:

    Row Labels Average of Time Elapsed (ms)
    Bitmap.Save(byteStream_ImageFormat.Png) 7.333433333
    Bitmap.Save(byteStream_oImgFile.RawFormat) 7.4263
    Bitmap.SelectActiveFrame(FrameDimension.Page_page)  3.083466667
    new System.Drawing.Bitmap(ImageFormat.Png) 1.881583333
    newSystem.Drawing.Bitmap(imageFromFile.RawFormat) 3.370933
    Grand Total 4.619143333

    Windows Server 2012 R2

    Row Labels Average of Time Elapsed (ms)
    Bitmap.Save(byteStream_ImageFormat.Png) 12.3031
    Bitmap.Save(byteStream_oImgFile.RawFormat) 16.303
    Bitmap.SelectActiveFrame(FrameDimension.Page_page)  8.2201
    new System.Drawing.Bitmap(ImageFormat.Png) 4.4245
    new System.Drawing.Bitmap(imageFromFile.RawFormat) 10.5204
    Grand Total 51.7711

    Please guide me solving this issue. Thank you!

    Monday, November 20, 2017 9:49 PM

All replies

  • We have a .NET application that reads the tiff files and displays it in the UI. We recently upgraded our servers from win 2008 to win 2012 r2 and started seeing serious performance issue with our application. We analyzed our code and found the following code execution to be comparatively slow in win 2012 R2 server compared to win 2008 server. We have .net framework 4.6 installed in both the machines.

    • Bitmap.Save(byteStream_ImageFormat.Png)
    • Bitmap.Save(byteStream_oImgFile.RawFormat)
    • Bitmap.SelectActiveFrame(FrameDimension.Page_page)
    • new System.Drawing.Bitmap(ImageFormat.Png)
    • new System.Drawing.Bitmap(imageFromFile.RawFormat)

    I have attached the full project as well as sample image along with this post (https://drive.google.com/file/d/1N8JK6lePqrRu_MiqFaYhoR5uwBrGDvU1/view).

    The sample image is small but in our real application the sample image is larger than this. Please find the comparison summary below:

    Our application performs 2-3 times slower in windows 2012 machine than compared to 2008 machine when dealing with the tiff images.

    Windows Server 2008

    Row Labels Average of Time Elapsed (ms)
    Bitmap.Save(byteStream_ImageFormat.Png) 7.333433333
    Bitmap.Save(byteStream_oImgFile.RawFormat) 7.4263
    Bitmap.SelectActiveFrame(FrameDimension.Page_page)  3.083466667
    new System.Drawing.Bitmap(ImageFormat.Png) 1.881583333
    new System.Drawing.Bitmap(imageFromFile.RawFormat) 3.370933333
    Grand Total 4.619143333

    Windows Server 2012 R2

    Row Labels

    Sum of Time Elapsed (ms)

    Bitmap.Save(byteStream_ImageFormat.Png)

    12.3031

    Bitmap.Save(byteStream_oImgFile.RawFormat)

    16.303

    Bitmap.SelectActiveFrame(FrameDimension.Page_page)

    8.2201

    new System.Drawing.Bitmap(ImageFormat.Png)

    4.4245

    new System.Drawing.Bitmap(imageFromFile.RawFormat)

    10.5204

    Grand Total

    51.7711

    Please guide me in solving this performance issue.

    Wednesday, November 15, 2017 12:21 AM
  • Hi Dear,

    Thank you for posting here.

    >>I have attached the full project as well as sample image along with this post (https://drive.google.com/file/d/1N8JK6lePqrRu_MiqFaYhoR5uwBrGDvU1/view).

    I try to download the source file from the link you provided, but there is something wrong, I could not download it.

    >>The sample image is small but in our real application the sample image is larger than this. Please find the comparison summary below:

    According to your description, have you try the image with the same size to test whether it cause the performance issue?

    Do you mean the image you test in 2012R2 is larger than the sample image you test in 2008?

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 16, 2017 2:28 AM
    Moderator

  • Were you able to see the download button while trying to download the project? If you cannot see it please let me know I will find alternative ways of getting the demo project to you. 

    Yes, I tried the same image in both the OS (Windows Server 2008 [not r2] and Windows Server 2012). I would like to let you know that we tried in multiple servers running two different OS with the same sets of images. Then, we reached the conclusion of Windows server 2012 r2 having slower performance than Windows server 2008 [not R2]. Again, I am reiterating that we used same exact same sets of images during our performance test in both the servers. In my question I actually meant that our production images are larger than sample image I have attached along with the project. I have attached one of the sample image along with the project, which we used for our performance test in windows 2008 server [not r2] as well as Windows 2012 server r2. 

    Please let me know if you have any questions.




    Thursday, November 16, 2017 3:08 PM
  • You should be able to see the download button while downloading the zipped project. I have tried downloading this from multiple browsers including the internet explorer. It works for me. If you cannot download, I will try to send you the project using alternative ways. Thank you!

    If helpful following is the project code.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace ImageViewerTest
    {
        public partial class Form1 : Form
        {
            private string[] files;
            public Form1()
            {
                InitializeComponent();
            }

            private void runButton_Click(object sender, EventArgs e)
            {
                try
                {
                    if (string.IsNullOrEmpty(imageFilePath.Text) || 
                        (!imageFilePath.Text.StartsWith("Multiple") && !File.Exists(imageFilePath.Text)))
                    {
                        MessageBox.Show("Missing file name or file doesn't exist");
                    }
                    else
                    {
                        if(!imageFilePath.Text.StartsWith("Multiple"))
                        {
                            files = new string[] { imageFilePath.Text };
                        }

                        var logFile = Path.Combine(
                           Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "ImageViewerTestLog.csv");

                        // Truncate the file
                        File.WriteAllText(logFile, "");
                        StringBuilder results = new StringBuilder();
                        var separator = ",";
                        results.Append("\"File Name\"" + separator + "Page" + separator + "Date" + separator + "API Call" + separator + "Time Elapsed (ms)" + separator + "Image Format" + Environment.NewLine);
                        var timestamp = "yyyy-MM-dd-HH:mm:ss";
                        foreach (string filePath in files)
                        {
                            var imageFile = new FileInfo(filePath);
                            var stopWatch = new Stopwatch();
                            stopWatch.Reset();
                            stopWatch.Start();
                            Bitmap imageFromFile = new Bitmap(filePath);
                            stopWatch.Stop();
                            int count = imageFromFile.GetFrameCount(FrameDimension.Page);
                            var fileName = "\"" + imageFile.Name + "\"";
                            results.Append(fileName + separator + (count) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "new Bitmap(filePath)" + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + "NA" + Environment.NewLine);

                            
                            for (int page = 0; page < count; page++)
                            {
                                // Measure Bitmap.SelectActiveFrame
                                stopWatch.Reset();
                                stopWatch.Start();
                                imageFromFile.SelectActiveFrame(FrameDimension.Page, page);
                                stopWatch.Stop();
                                results.Append(fileName + separator + (page + 1) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "Bitmap.SelectActiveFrame(FrameDimension.Page_page) " + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + "NA" + Environment.NewLine);

                                // Measure Bitmap.Save using Png
                                var byteStreamPNG = new MemoryStream();
                                stopWatch.Reset();
                                stopWatch.Start();
                                imageFromFile.Save(byteStreamPNG, ImageFormat.Png);
                                stopWatch.Stop();
                                results.Append(fileName + separator + (page + 1) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "Bitmap.Save(byteStream_ImageFormat.Png)" + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + ImageFormat.Png.ToString() + Environment.NewLine);

                                // Measure Bitmap.Save using original format
                                var byteStreamRawFormat = new MemoryStream();
                                stopWatch.Reset();
                                stopWatch.Start();
                                imageFromFile.Save(byteStreamRawFormat, imageFromFile.RawFormat);
                                stopWatch.Stop();
                                results.Append(fileName + separator + (page + 1) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "Bitmap.Save(byteStream_oImgFile.RawFormat)" + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + imageFromFile.RawFormat.ToString() + Environment.NewLine);

                                // Measure new System.Drawing.Bitmap using Png
                                stopWatch.Reset();
                                stopWatch.Start();
                                var imagePNG = new System.Drawing.Bitmap(byteStreamPNG);
                                stopWatch.Stop();
                                results.Append(fileName + separator + (page + 1) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "new System.Drawing.Bitmap(ImageFormat.Png)" + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + ImageFormat.Png.ToString() + Environment.NewLine);
                                imagePNG.Dispose();

                                // Measure new System.Drawing.Bitmap using original format
                                stopWatch.Reset();
                                stopWatch.Start();
                                var imageRawFormat = new System.Drawing.Bitmap(byteStreamRawFormat);

                                stopWatch.Stop();
                                results.Append(fileName + separator + (page + 1) + separator + DateTime.Now.ToString(timestamp) + separator +
                                    "new System.Drawing.Bitmap(imageFromFile.RawFormat)" + separator +
                                    stopWatch.Elapsed.TotalMilliseconds.ToString() + separator + imageFromFile.RawFormat.ToString() + Environment.NewLine);
                                imageRawFormat.Dispose();
                                byteStreamRawFormat.Dispose();
                            }

                            File.AppendAllText(logFile, results.ToString());
                            results.Clear();
                            imageFromFile.Dispose();

                        }

                        MessageBox.Show("Done!");
                    }
                }
                catch (Exception ex)
                {
                    var st = new StackTrace(ex, true);
                    var logFile = Path.Combine(
                           Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "Error.txt");
                    MessageBox.Show(ex.StackTrace.ToString(), "Excetion:");
                    File.WriteAllText(logFile, st.ToString()+"\n"+ex);
                }
            }

            private void fileExplorerButton_Click(object sender, EventArgs e)
            {
                imageFilePath.Text = this.BrowseFile();
            }
            string BrowseFile()
            {
                try
                {
                    dlgopenImageFileDialog.Filter = "Image Files(*.TIF;*.TIFF;*.BMP;*.JPG;*.GIF)|*.TIF;*.TIFF;*.BMP;*.JPG;*.GIF|All files (*.*)|*.*";
                    dlgopenImageFileDialog.Title = "Select an image file";
                    dlgopenImageFileDialog.Multiselect = true;
                    dlgopenImageFileDialog.FileName = String.Empty;
                    if (dlgopenImageFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        files = dlgopenImageFileDialog.FileNames;
                        if (files != null && files.Length > 0)
                        {
                            return "Multiple files selected";
                        }
                        else
                        {
                            return dlgopenImageFileDialog.FileName;
                        }
                    }
                }
                catch
                {
                    return string.Empty;
                }

                return string.Empty;
            }
        }
    }


    Thursday, November 16, 2017 3:16 PM
  • Hi Swastik Singh,

    Thank you for feedback.

    I try to create environment to reproduce. It needs some time. If I have something new, I will give something back.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, November 22, 2017 2:03 AM
    Moderator
  • Hi Swastil Singh,

    I create Windows server 2012 R2 to test the code. But Windows server 2008 is not supported. I could not get the environment of Windows Server 2008. Hence I could not compare the efficiency of the code.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, November 27, 2017 2:38 AM
    Moderator
  • We are trying to move our stuffs from Windows 2008 to Windows 2012R2. This performance issue is still a bottleneck in our end and hampering the windows upgrade. The performance problem here is in the windows 2012r2 server. 

    1. What would you suggest us to do in this scenario?

    2. Has anyone posted issue in this area?

    Please let me know if I need to contact or post this issue to any other platform.

    Thank you,

    Swastik Singh

    Tuesday, January 9, 2018 6:16 PM