What cause high CPU usage on the server during file upload

Posted by bosiang on Server Fault See other posts from Server Fault or by bosiang
Published on 2012-06-28T19:13:11Z Indexed on 2012/06/28 21:18 UTC
Read the original article Hit count: 206

Filed under:
|
|
|

When I try to upload a huge file size (approx 2GB), the server cpu usage goes really high. What should I do to fix this?

I just use standard html form and php, for file upload.

I'm sorry if I post on the wrong forum. Please point me to the right direction

here is the result of "top" command during uploading 4 files (18mb, 38mb, 60mb, 33mb)

 1904 apache    20   0 33504 5740 1952 R 28.3  0.2   0:02.19 httpd
 1905 apache    20   0 33504 5740 1952 R 28.3  0.2   0:01.99 httpd
 1903 apache    20   0 33232 6968 3060 R 28.0  0.2   0:01.98 httpd
 1910 apache    20   0 33240 6020 2248 S 11.5  0.2   0:02.85 httpd
 2133 root      20   0  2656 1124  896 R  1.6  0.0   0:00.71 top
    1 root      20   0  2864 1404 1188 S  0.0  0.0   0:03.99 init

the code for chunking, although eventhough I don't use this code (just simple file upload), it still cause that high cpu usage function sendRequest() {
//clean the screen //bars.innerHTML = '';

            var file = document.getElementById('fileToUpload');   

            for(var i = 0; i < file.files.length; i++) {      
                var blob = file.files[i];
                var originalFileName = blob.name;
                var filePart = 0

                const BYTES_PER_CHUNK = 100 * 1024 * 1024; // 10MB chunk sizes.
                var realFileSize = blob.size;

                var start = 0;
                var end = BYTES_PER_CHUNK;

                totalChunks = Math.ceil(realFileSize / BYTES_PER_CHUNK);

                alert(realFileSize);
                while( start < realFileSize ) { 

                    if (blob.webkitSlice) {
                        //for Google Chrome
                        var chunk = blob.webkitSlice(start, end); 
                    } else if (blob.mozSlice) {
                        //for Mozilla Firefox
                        var chunk = blob.mozSlice(start, end);

                    }       

                    uploadFile(chunk, originalFileName, filePart, totalChunks, i);

                    filePart++;
                    start = end;
                    end = start + BYTES_PER_CHUNK;
                }
            }                
        }

© Server Fault or respective owner

Related posts about linux

Related posts about centos