Re: Unable to transfer file above 60mb in Tomcat

2022-05-03 Thread Christopher Schultz

Mark,

On 5/3/22 02:26, Mark Thomas wrote:
The code uses memory inefficiently and the JVM is not configured with 
enough memory to handle the load.


+1


One of the following should solve this:

1. Re-write the server code to read the file contents from a 
FileInputStream and write it directly to a ServletOutputStream. Don't 
copy it to a String first as that means you have to keep the entire file 
in memory rather than the part you are copying at the time.


+1

Or just use sendfile[1], since the data is already in a file.


2. Increase the memory available to your JVM.

You might want to consider re-writing the client code for the same reason.


+1

-chris

[1] https://tomcat.apache.org/tomcat-9.0-doc/aio.html


On 02/05/2022 08:09, dku...@ccilindia.co.in.INVALID wrote:

Dear team,

I have a file copy application, that run between tomcat server and java
client. Its copy file from server end to paste at client end.

At server end code written in Servlet file. Its read file data and file
name from file. And storing it into String object and send it to 
client in

response.
At server end we are creating file using above data and file name.
I have shared code snipped below.
-- Server end --
--
 File fromFolderSec = new File("folder path");
    File[] sendfile = fromFolderSec.listFiles();
    File[] var28 = sendfile;
 String filesContent = null;
 File file = sendfile[0];
 String currFileName = file.getName();
    try {
 filesName.add(file.getName());
   FileInputStream fis = new FileInputStream(file);
   int arraysize = fis.available();
   StringBuffer sb = new StringBuffer();
 int i;
   for(i = 0; i < arraysize; ++i) {
 sb.append((char)fis.read());
   }
   filesContent.add(sb.toString());
   fis.close();
 } catch (StringIndexOutOfBoundsException var36) {
   System.out.println( " Exception occurred while sending
file: Exc=" + var36.getMessage());
 }

---Client end -
 File toFolderSec = new File("Folder path");
   try {
 File ffile = null;
 File tempFolder = new 
File(toFolderSec.getPath());

 ffile = new File(toFolderSec.getPath() + "//" +
currFileName);
 BufferedWriter bw = new BufferedWriter(new
FileWriter(ffile));
 String data = filesContent.get(0);
 bw.write(data);
 bw.flush();
 bw.close();
 } catch (Exception  var36) {
 System.out.println( " Exception  Exc=" +
var36.getMessage());
    }
---

This code was working fine on HPunix. Recently we have migrated our 
server

to IBM Linux1. After migration application getting stuck while sending
file size more than 60mb.  Below 60mb its working fine.

Some error file has gerated in tomcat/bin folder Out of that sharing one
file details below
File name -- javacore.20220427.122826.201959.0012.txt

1TISIGINFO Dump Event "systhrow" (0004) Detail
"java/lang/OutOfMemoryError" "Java heap space" received

1CIUSERLIMITS  User Limits (in bytes except for NOFILE and NPROC)
NULL

NULL   type    soft limit   hard
limit
2CIUSERLIMIT   RLIMIT_AS    unlimited unlimited
2CIUSERLIMIT   RLIMIT_CORE  unlimited unlimited
2CIUSERLIMIT   RLIMIT_CPU   unlimited unlimited
2CIUSERLIMIT   RLIMIT_DATA  unlimited unlimited
2CIUSERLIMIT   RLIMIT_FSIZE unlimited unlimited
2CIUSERLIMIT   RLIMIT_LOCKS unlimited unlimited
2CIUSERLIMIT   RLIMIT_MEMLOCK   65536 65536
2CIUSERLIMIT   RLIMIT_NOFILE    10240 10240
2CIUSERLIMIT   RLIMIT_NPROC  4096 180193
2CIUSERLIMIT   RLIMIT_RSS   unlimited unlimited
2CIUSERLIMIT   RLIMIT_STACK 838860800 838860800
2CIUSERLIMIT   RLIMIT_MSGQUEUE 819200 819200
2CIUSERLIMIT   RLIMIT_NICE  0   0
2CIUSERLIMIT   RLIMIT_RTPRIO    0   0
2CIUSERLIMIT   RLIMIT_SIGPENDING    55347 55347

0SECTION   NATIVEMEMINFO subcomponent dump routine
NULL   =
0MEMUSER
1MEMUSER   JRE: 1,085,352,584 bytes / 20226 allocations
1MEMUSER   |
2MEMUSER   +--VM: 798,286,440 bytes / 16812 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Classes: 30,652,464 bytes / 889 allocations

Re: Unable to transfer file above 60mb in Tomcat

2022-05-03 Thread Mark Thomas
There isn't a question in the post below. I am assuming that the implied 
question is "why doesn't this work?".


The code uses memory inefficiently and the JVM is not configured with 
enough memory to handle the load.


One of the following should solve this:

1. Re-write the server code to read the file contents from a 
FileInputStream and write it directly to a ServletOutputStream. Don't 
copy it to a String first as that means you have to keep the entire file 
in memory rather than the part you are copying at the time.


2. Increase the memory available to your JVM.

You might want to consider re-writing the client code for the same reason.

Mark


On 02/05/2022 08:09, dku...@ccilindia.co.in.INVALID wrote:

Dear team,

I have a file copy application, that run between tomcat server and java
client. Its copy file from server end to paste at client end.

At server end code written in Servlet file. Its read file data and file
name from file. And storing it into String object and send it to client in
response.
At server end we are creating file using above data and file name.
I have shared code snipped below.
-- Server end --
--
 File fromFolderSec = new File("folder path");
File[] sendfile = fromFolderSec.listFiles();
File[] var28 = sendfile;
 String filesContent = null;
 File file = sendfile[0];
 String currFileName = file.getName();
try {
 filesName.add(file.getName());
   FileInputStream fis = new FileInputStream(file);
   int arraysize = fis.available();
   StringBuffer sb = new StringBuffer();
 int i;
   for(i = 0; i < arraysize; ++i) {
 sb.append((char)fis.read());
   }
   filesContent.add(sb.toString());
   fis.close();
 } catch (StringIndexOutOfBoundsException var36) {
   System.out.println( " Exception occurred while sending
file: Exc=" + var36.getMessage());
 }

---Client end -
 File toFolderSec = new File("Folder path");
   try {
 File ffile = null;
 File tempFolder = new File(toFolderSec.getPath());
 ffile = new File(toFolderSec.getPath() + "//" +
currFileName);
 BufferedWriter bw = new BufferedWriter(new
FileWriter(ffile));
 String data = filesContent.get(0);
 bw.write(data);
 bw.flush();
 bw.close();
 } catch (Exception  var36) {
 System.out.println( " Exception  Exc=" +
var36.getMessage());
}
  
---


This code was working fine on HPunix. Recently we have migrated our server
to IBM Linux1. After migration application getting stuck while sending
file size more than 60mb.  Below 60mb its working fine.

Some error file has gerated in tomcat/bin folder Out of that sharing one
file details below
File name -- javacore.20220427.122826.201959.0012.txt

1TISIGINFO Dump Event "systhrow" (0004) Detail
"java/lang/OutOfMemoryError" "Java heap space" received

1CIUSERLIMITS  User Limits (in bytes except for NOFILE and NPROC)
NULL

NULL   typesoft limit   hard
limit
2CIUSERLIMIT   RLIMIT_ASunlimited unlimited
2CIUSERLIMIT   RLIMIT_CORE  unlimited unlimited
2CIUSERLIMIT   RLIMIT_CPU   unlimited unlimited
2CIUSERLIMIT   RLIMIT_DATA  unlimited unlimited
2CIUSERLIMIT   RLIMIT_FSIZE unlimited unlimited
2CIUSERLIMIT   RLIMIT_LOCKS unlimited unlimited
2CIUSERLIMIT   RLIMIT_MEMLOCK   65536 65536
2CIUSERLIMIT   RLIMIT_NOFILE10240 10240
2CIUSERLIMIT   RLIMIT_NPROC  4096 180193
2CIUSERLIMIT   RLIMIT_RSS   unlimited unlimited
2CIUSERLIMIT   RLIMIT_STACK 838860800 838860800
2CIUSERLIMIT   RLIMIT_MSGQUEUE 819200 819200
2CIUSERLIMIT   RLIMIT_NICE  0   0
2CIUSERLIMIT   RLIMIT_RTPRIO0   0
2CIUSERLIMIT   RLIMIT_SIGPENDING55347 55347

0SECTION   NATIVEMEMINFO subcomponent dump routine
NULL   =
0MEMUSER
1MEMUSER   JRE: 1,085,352,584 bytes / 20226 allocations
1MEMUSER   |
2MEMUSER   +--VM: 798,286,440 bytes / 16812 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Classes: 30,652,464 bytes / 889 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Memory Manager (GC): 

Unable to transfer file above 60mb in Tomcat

2022-05-02 Thread dkumar
Dear team,

I have a file copy application, that run between tomcat server and java 
client. Its copy file from server end to paste at client end. 

At server end code written in Servlet file. Its read file data and file 
name from file. And storing it into String object and send it to client in 
response. 
At server end we are creating file using above data and file name.
I have shared code snipped below. 
-- Server end -- 
--
File fromFolderSec = new File("folder path");
   File[] sendfile = fromFolderSec.listFiles(); 
   File[] var28 = sendfile;
String filesContent = null;
File file = sendfile[0];
String currFileName = file.getName();
   try {
filesName.add(file.getName()); 
  FileInputStream fis = new FileInputStream(file);
  int arraysize = fis.available(); 
  StringBuffer sb = new StringBuffer();
int i;
  for(i = 0; i < arraysize; ++i) {
sb.append((char)fis.read());
  }
  filesContent.add(sb.toString());
  fis.close();
} catch (StringIndexOutOfBoundsException var36) {
  System.out.println( " Exception occurred while sending 
file: Exc=" + var36.getMessage());
}

---Client end -
File toFolderSec = new File("Folder path");
  try {
File ffile = null;
File tempFolder = new File(toFolderSec.getPath());
ffile = new File(toFolderSec.getPath() + "//" + 
currFileName); 
BufferedWriter bw = new BufferedWriter(new 
FileWriter(ffile));
String data = filesContent.get(0);
bw.write(data);
bw.flush();
bw.close(); 
} catch (Exception  var36) {
System.out.println( " Exception  Exc=" + 
var36.getMessage());
   }
 
---

This code was working fine on HPunix. Recently we have migrated our server 
to IBM Linux1. After migration application getting stuck while sending 
file size more than 60mb.  Below 60mb its working fine.

Some error file has gerated in tomcat/bin folder Out of that sharing one 
file details below
File name -- javacore.20220427.122826.201959.0012.txt 

1TISIGINFO Dump Event "systhrow" (0004) Detail 
"java/lang/OutOfMemoryError" "Java heap space" received

1CIUSERLIMITS  User Limits (in bytes except for NOFILE and NPROC)
NULL 

NULL   typesoft limit   hard 
limit
2CIUSERLIMIT   RLIMIT_ASunlimited unlimited
2CIUSERLIMIT   RLIMIT_CORE  unlimited unlimited
2CIUSERLIMIT   RLIMIT_CPU   unlimited unlimited
2CIUSERLIMIT   RLIMIT_DATA  unlimited unlimited
2CIUSERLIMIT   RLIMIT_FSIZE unlimited unlimited
2CIUSERLIMIT   RLIMIT_LOCKS unlimited unlimited
2CIUSERLIMIT   RLIMIT_MEMLOCK   65536 65536
2CIUSERLIMIT   RLIMIT_NOFILE10240 10240
2CIUSERLIMIT   RLIMIT_NPROC  4096 180193
2CIUSERLIMIT   RLIMIT_RSS   unlimited unlimited
2CIUSERLIMIT   RLIMIT_STACK 838860800 838860800
2CIUSERLIMIT   RLIMIT_MSGQUEUE 819200 819200
2CIUSERLIMIT   RLIMIT_NICE  0   0
2CIUSERLIMIT   RLIMIT_RTPRIO0   0
2CIUSERLIMIT   RLIMIT_SIGPENDING55347 55347

0SECTION   NATIVEMEMINFO subcomponent dump routine
NULL   =
0MEMUSER
1MEMUSER   JRE: 1,085,352,584 bytes / 20226 allocations
1MEMUSER   |
2MEMUSER   +--VM: 798,286,440 bytes / 16812 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Classes: 30,652,464 bytes / 889 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Memory Manager (GC): 549,215,240 bytes / 783 
allocations
3MEMUSER   |  |  |
4MEMUSER   |  |  +--Java Heap: 536,932,352 bytes / 1 allocation
3MEMUSER   |  |  |
4MEMUSER   |  |  +--Other: 12,282,888 bytes / 782 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Threads: 16,317,048 bytes / 257 allocations
3MEMUSER   |  |  |
4MEMUSER   |  |  +--Java Stack: 398,744 bytes / 35 allocations
3MEMUSER   |  |  |
4MEMUSER   |  |  +--Native Stack: 15,597,568 bytes / 36 allocations
3MEMUSER   |  |  |
4MEMUSER   |  |  +--Other: 320,736 bytes / 186 allocations
2MEMUSER   |  |
3MEMUSER   |  +--Trace: 730,496 bytes / 2948 allocations
2MEMUSER   |  |
3MEMUSER   |  +--JVMTI: 17,776 bytes / 13 allocations
2MEMUSER