# squid -> ulimit



## ccc (Jun 17, 2009)

hi

According to this webpage:

http://www.linux-faqs.com/squid.php

I'd like to optimize my squid 2.7.STABLE6 installed on freeBSD 7.0 (P4, 2GHz, 2GB RAM) for about 150 users.

I should put the following two lines:

ulimit -HSn 8192 echo 1024 32768 > /proc/sys/net/ipv4/ip_local_port_range

to the startup script /usr/local/etc/rc.d/squid, but I don't know where exactly.

my /usr/local/etc/rc.d/squid
	
	



```
#!/bin/sh
#
# $FreeBSD: ports/www/squid/files/squid.in,v 1.3 2007/08/14 02:32:11 delphij Exp $
#
# PROVIDE: squid
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Note:
# Set "squid_enable=yes" in either /etc/rc.conf, /etc/rc.conf.local or
# /etc/rc.conf.d/squid to make this script actually do something. There
# you can also set squid_chdir, squid_pidfile, squid_user, and squid_flags.
#
# Please see squid(8), rc.conf(5) and rc(8) for further details.
#

squid_checkrunning() {
	${command} ${squid_flags} -k check 2>/dev/null
}

squid_stop() {
	echo "Stopping ${name}."
	${command} ${squid_flags} -k shutdown
	run_rc_command poll
}

. /etc/rc.subr

name=squid
rcvar=${name}_enable

command=/usr/local/sbin/squid
extra_commands=reload
reload_cmd="${command} ${squid_flags} -k reconfigure"
stop_precmd="squid_checkrunning"
stop_cmd="squid_stop"

load_rc_config ${name}

squid_chdir=${squid_chdir:-"/usr/local/squid/logs"}
squid_enable=${squid_enable:-"NO"}
squid_flags=${squid_flags-"-D"}
squid_pidfile=${squid_pidfile:-"/usr/local/squid/logs/squid.pid"}
squid_user=${squid_user:-squid}
default_config=/usr/local/etc/squid/squid.conf

pidfile=${squid_pidfile}
required_dirs=${squid_chdir}

# squid(8) will not start if ${default_config} is not present so try
# to catch that beforehand via ${required_files} rather than make
# squid(8) crash.
# If you remove the default configuration file make sure to add
# '-f /path/to/your/squid.conf' to squid_flags

if [ -z "${squid_flags}" ]; then
	required_files=${default_config}
fi

run_rc_command "$1"
```


----------



## SirDice (Jun 17, 2009)

ccc said:
			
		

> ulimit -HSn 8192 echo 1024 32768 > /proc/sys/net/ipv4/ip_local_port_range
> 
> to the startup script /usr/local/etc/rc.d/squid, but I don't know where exactly.


It won't work anyway. FreeBSD doesn't use /proc like Linux does. Most of the kernel parameters that are configured using /proc on linux can be set using sysctl on FreeBSD.

You will need to interpret the output of that command and set the correct sysctl yourself. To make sure they're set during boot add them to /etc/sysctl.conf.


```
root@molly:~#sysctl -a | grep range
net.inet.ip.portrange.randomtime: 45
net.inet.ip.portrange.randomcps: 10
net.inet.ip.portrange.randomized: 1
net.inet.ip.portrange.reservedlow: 0
net.inet.ip.portrange.reservedhigh: 1023
net.inet.ip.portrange.hilast: 65535
net.inet.ip.portrange.hifirst: 49152
net.inet.ip.portrange.last: 65535
net.inet.ip.portrange.first: 49152
net.inet.ip.portrange.lowlast: 600
net.inet.ip.portrange.lowfirst: 1023
```

Edit: Err.. ulimit doesn't exist either. Figure out what it's supposed to show and have a look with limits(1) and sysctl(8).


----------



## ccc (Jun 17, 2009)

thx, I'm getting this:
	
	



```
# sysctl -a | grep range
net.inet.ip.portrange.randomtime: 45
net.inet.ip.portrange.randomcps: 10
net.inet.ip.portrange.randomized: 1
net.inet.ip.portrange.reservedlow: 0
net.inet.ip.portrange.reservedhigh: 1023
net.inet.ip.portrange.hilast: 65535
net.inet.ip.portrange.hifirst: 49152
net.inet.ip.portrange.last: 65535
net.inet.ip.portrange.first: 49152
net.inet.ip.portrange.lowlast: 600
net.inet.ip.portrange.lowfirst: 1023
p1003_1b.memlock_range: 0

# lsof -u squid | wc -l
      267
```

Knows someone howto set limits for squid in /etc/sysctl.conf?


----------



## SirDice (Jun 17, 2009)

If I look at what /proc/sys/net/ipv4/ip_local_port_range does it seems to set hifirst and hilast to 1024 and 32768 resp.


----------



## ccc (Jun 17, 2009)

SirDice said:
			
		

> If I look at what /proc/sys/net/ipv4/ip_local_port_range does it seems to set hifirst and hilast to 1024 and 32768 resp.



this directory doesn't exists on my system:
	
	



```
# cat /proc/sys/net/ipv4/ip_local_port_range
cat: /proc/sys/net/ipv4/ip_local_port_range: No such file or directory
bsd# ls -la /proc
total 4
dr-xr-xr-x   2 root  <<<<<<< current   512 Feb  3  2008 .
drwxr-xr-x  21 root  <<<<<<< current   512 Jun 16 12:26 ..
```


----------



## vivek (Jun 17, 2009)

Do not follow that guide. Info is even outdated for Linux too. These days everything can be controlled by editing /etc/sysctl.conf on both Linux and FreeBSD. Set the following at freebsd to increase ranges by editing /etc/sysctl.conf:

```
net.inet.ip.portrange.last=65535
net.inet.ip.portrange.first=1024 
kern.maxfilesperproc=8192
kern.maxfiles=65535
```
Type the following at a shell prompt

```
sysctl net.inet.ip.portrange.last=65535
sysctl net.inet.ip.portrange.first=1024 
sysctl kern.maxfilesperproc=8192
sysctl kern.maxfiles=65535
```

Now, FreeBSD just increased ranges. Restart squid and see log file or type the following to get range:

```
squidclient mgr:info | grep 'file descri'
```


----------



## ccc (Jun 17, 2009)

thx, I've done and now get the following:
	
	



```
# squidclient mgr:info | grep 'file descri'
        Maximum number of file descriptors:   7178
        Available number of file descriptors: 7161
        Reserved number of file descriptors:   100
```


----------



## vivek (Jun 17, 2009)

Yes, I know  it should work - we run some fatty squid server for 1000+ desktops here. BTW, you should edit original post and add [Solved] prefix.


----------

