How to change allocated memory for a process?

Hello,
I am running ubuntu 14.04 in a server with 32GB ram.
Due to receiving "high load" errors during ssh connection, I took a look at what's happening from command line. I detected that 20GB of total memory was allocated to a program.
Below you can see some initial part of installation script. As I believed this issue is not classified as shell scripting issue, I opened the thread under "general & beginners" field. Hope I am right.

#!/bin/sh
chmod 777 *.*
chmod 777 *
echo 2062780 > /proc/sys/kernel/threads-max
if ! cat /etc/sysctl.conf | grep -v grep | grep -c 1677721600 > /dev/null; then
echo 'net.core.wmem_max= 1677721600' >> /etc/sysctl.conf
echo 'net.core.rmem_max= 1677721600' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem= 1024000 8738000 1677721600' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem= 1024000 8738000 1677721600' >> /etc/sysctl.conf
echo 'net.ipv4.udp_mem =1024000 8738000 1677721600' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_window_scaling = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_timestamps = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_sack = 1' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_no_metrics_save = 1' >> /etc/sysctl.conf
echo 'net.core.netdev_max_backlog = 5000' >> /etc/sysctl.conf
echo 'net.ipv4.route.flush=1' >> /etc/sysctl.conf
echo 'fs.file-max=65536' >> /etc/sysctl.conf
sysctl -p
fi
#...
#..
#.
#the rest of the code is related to installation of the application

Do you think that when I change "2062780" to half of the value, could it be the solution and what about other values? I believe 1031390 memory is enough for this application as it was not much busy.

free -m

             total       used       free     shared    buffers     cached
Mem:         31882      30995        887          8        263      19988
-/+ buffers/cache:      10742      21139
Swap:         4093          0       4093

cat /proc/meminfo

MemTotal:       32648164 kB
MemFree:          267172 kB
MemAvailable:   21145252 kB
Buffers:          270424 kB
Cached:         20632720 kB
SwapCached:            0 kB
Active:         14189768 kB
Inactive:       16692520 kB
Active(anon):    8927760 kB
Inactive(anon):  1063128 kB
Active(file):    5262008 kB
Inactive(file): 15629392 kB
Unevictable:        9548 kB
Mlocked:            9548 kB
SwapTotal:       4192248 kB
SwapFree:        4192248 kB
Dirty:           3240844 kB
Writeback:        178960 kB
AnonPages:       9969652 kB
Mapped:            67196 kB
Shmem:              8300 kB
Slab:             526704 kB
SReclaimable:     454312 kB
SUnreclaim:        72392 kB
KernelStack:       14784 kB
PageTables:        38632 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:    20516328 kB
Committed_AS:   11570060 kB
VmallocTotal:   34359738367 kB
VmallocUsed:           0 kB
VmallocChunk:          0 kB
HardwareCorrupted:     0 kB
AnonHugePages:   5294080 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
DirectMap4k:       14560 kB
DirectMap2M:     2772992 kB
DirectMap1G:    30408704 kB

My /etc/sysctl.conf file:

net.core.somaxconn = 65535
net.ipv4.route.flush=1
net.ipv4.tcp_no_metrics_save=1
net.ipv4.tcp_moderate_rcvbuf = 1
fs.file-max = 6815744
fs.aio-max-nr = 6815744
fs.nr_open = 6815744
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_sack = 1
net.ipv4.tcp_rmem = 10000000 10000000 10000000
net.ipv4.tcp_wmem = 10000000 10000000 10000000
net.ipv4.tcp_mem = 10000000 10000000 10000000
net.core.rmem_max = 524287
net.core.wmem_max = 524287
net.core.rmem_default = 524287
net.core.wmem_default = 524287
net.core.optmem_max = 524287
net.core.netdev_max_backlog = 300000
net.ipv4.tcp_max_syn_backlog = 300000
net.netfilter.nf_conntrack_max=1215196608
net.ipv4.tcp_window_scaling = 1
vm.max_map_count = 655300
net.ipv4.tcp_max_tw_buckets = 1440000
kernel.shmmax=134217728
kernel.shmall=134217728
net.core.wmem_max= 1677721600
net.core.rmem_max= 1677721600
net.ipv4.tcp_rmem= 1024000 8738000 1677721600
net.ipv4.tcp_wmem= 1024000 8738000 1677721600
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_no_metrics_save = 1
net.core.netdev_max_backlog = 5000
net.ipv4.route.flush=1
fs.file-max=65536

I'd appreciate your comments.

Thank you
Boris

The only 2062780 I see in your code snippet is being written to the kernel parameter "threads-max", the maximum allowed processes / threads on the system. What makes you think this has to do with memory allocation?

Hello Rudic,
I expect to get rid of "high load" warning when I connect to server via ssh. I also read some other solutions regarding /etc/ssh/sshd_config in many boards but those explanations did not solve the issue.
Assumption: As there is no allocated memory for other processes, it stucks. If other processes have more ram to use, system load will be lower. (Just an assumption)

Thanks
Boris

Your swap consumption and "MemAvailable" indicate there's no memory shortage. Is that "high load" an ssh message? Does it mayhap refer to CPU load? What be the CPU load when you log in?

Hello Rudic,
I am sorry for my delayed return. When I connect to ubuntu via ssh, it shows info about status, you know it.
At that moment, normally I could see system load as percent. As you said, there is no relation with ssh and system load.
First I thought there were some misconfigured parameters in sshd_config file but could not have found any clue causing this issue. I made some changes at running processes and it's okay so far.

Thank you for your time
Boris