On JAVA, a socket server is implemented, the database is PostgreSQL. The problem is that when sending JSON messages of 1,500,000 characters in size, the memory grows by an average of 20 MB, when receiving JSON back it is already 60 MB. A JSON parser is used, an exemplary implementation of processing incoming messages:
public static void main(String args[]) { try { Integer b = 0; a = new ServerSocket(8572); new conf("server.json"); ms = new mysql(); ps = new postgresql(); System.out.println("[ur.java] Server started!"); while(true) new ur(b++, a.accept()); } catch(Exception e) { e.printStackTrace(); } } public ur(Integer a, Socket b) throws IOException { this.cb = a; this.ca = b; q.offer(this); ty = new type(this); setDaemon(true); setPriority(MAX_PRIORITY); start(); System.out.println("[ur.java] Machine "+a+" in socket stream!"); br = new BufferedReader(new InputStreamReader(ca.getInputStream(), "UTF-8")); } public void run() { try { String s; while ((s = br.readLine()) != null) ty.data(s.trim()); } catch (Exception e) { e.printStackTrace(); } }
Outgoing messages from the database:
ResultSet rs = connection.createStatement().executeQuery("bla bla"); if(rs.next()) { socket.getOutputStream().write((rs.getString(1)+"\0").getBytes("UTF-8")); }
Since the project consists of a heap of classes, it’s really impossible to lay out everything important, if some kind person has a desire to help, it would be ideal to contact via Skype
-Xms
. first heap, second stack, for examplejava -Xmx1024M -Xms512M your_server
- KoVadim