1

I am assigned the task to limit the resources (Maximum memory usage and CPU weight) for Apache2 and nginx according to usage statistics, and test that limitation.

For resource limitations, I've chosen the easy way -- to implement it via systemd's resource control by running apache2 & nginx in a custom limited slice:

limiter.slice:

[Unit]
Description=Resource limiting test
Before=slices.target

[Slice]
CPUWeight=50
MemoryMax=800M

[Install]
WantedBy=multi-user.target

And of course added the Slice=limiter.slice option to apache2 & nginx service files.

Now, nginx and apache2 correctly start in the limited slice (checked with systemctl status limiter.slice):

● limiter.slice - Resource limiting test
   Loaded: loaded (/etc/systemd/system/limiter.slice; enabled; vendor preset: enabled)
   Active: active since Wed 2018-07-18 16:07:59 EEST; 3s ago
    Tasks: 58
   Memory: 8.1M (max: 800.0M)
      CPU: 82ms
   CGroup: /limiter.slice
           ├─apache2.service
           │ ├─1823 /usr/sbin/apache2 -k start
           │ ├─1841 /usr/sbin/apache2 -k start
           │ └─1843 /usr/sbin/apache2 -k start
           └─nginx.service
             ├─1805 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
             ├─1808 nginx: worker process
             └─1811 nginx: worker process

I believe that the resource limitation should work. However, I do not have access to any heavily-used apache/nginx servers, so I cannot get close to even making apache2/nginx use that much RAM. And my task is to show what happens when Apache2/Nginx start using that much memory, and it has to be realistic, it really has to be that much RAM, and they do want me to show those web servers running with almost as much RAM usage. You can ignore the CPU Weight, as it is not my main focus.

So, in other words, I need to somehow increase/inflate the RAM usage of those web servers.

  1. Is the way I'm trying to limit their resource usage a good practice (via systemd slice resource-control)?
  2. How to go about increasing Apache & Nginx webservers' memory usage (to about 800M RAM, if possible even higher)?

My machine has 6G RAM, I'm okay with using 2-3G RAM for test cases.
Running Linux Debian 9.4.
Apache2 version:
Server version: Apache/2.4.25 (Debian)
Nginx version:
nginx version: nginx/1.10.3

Note: Apache2 web server is the main focus, doing the same for Nginx is not necessary, it's just a bonus for research.

I've tried to find any ways to benchmark RAM usage, but failed. Keep in mind that I'm doing this on a normal workstation, thus there's no easy way to deploy apps on the web servers and generate enough traffic naturally in order to get such an increase in memory usage.

Update: I managed to get apache + nginx consuming up to 400-500MB RAM by using heavy ab benchmarks all the time. However, I still can't test to see if they would be able to even reach the specified 800MB RAM limit. Any suggestions would be appreciated.

Fanatique
  • 61
  • 6
  • Why don't you set the limits lower to like 100MB and benchmark again? If it works with 100, it should with 800. – Lenniey Aug 03 '18 at 08:31
  • @Lenniey Because I specifically want to see if Apache or NGINX can reach such RAM usage. I want to make them use such amounts of RAM. – Fanatique Aug 03 '18 at 08:36
  • 1
    Install mod_php and write a PHP script to allocate a whole lot of memory. Aside from that, Apache (and nginx) don't really use a lot of memory. – Michael Hampton Aug 03 '18 at 15:04

2 Answers2

0

One way to increase the resource utilization of Apache is to use additional modules. PHP comes to mind as an easy way to increase the memory requirements.

If you do not want to use additional modules, increasing the memory can e.g. be caused by POSTing (uploading) large files (depending on configuration) or keeping HTTP requests in flight (not finishing the request, having slow clients in proxy mode, ...).

Testing that is generally not very easy as it requires additional resources and use-case-specific scripts / tooling on the test clients.

Bernhard
  • 971
  • 1
  • 5
  • 15
0

If all you're doing is HTTP requests served with static content, really the only way you're going to blow up the memory is to increase the concurrency of the connections during testing. I don't know what your use case is but if all you're trying to do is increase the memory usage then you might need to use mod_session to have apache save some session data server side. This will increase the duration and amount of memory consumed / connection server side. This may not, however, match your real world usage. The memory usage really depends on how the server is being used, and the architecture of your overall solution. Does the content being served in testing match the content that will be served in production? If not, then you're not going to get accurate results and your constraints might not be appropriate for your environment. To get accurate results you'll need to test typical usage scenarios for your existing solution. If there's more than 1 server you'll need to take into account that there may be failures and some of the traffic will then have to be handled by the remaining server(s). Other than getting apache to eat up RAM, what exactly is the point of your testing? I'm a software tester so I can help you, but I need more information in order to give you good advice on what you should be doing.

apocalysque
  • 419
  • 3
  • 8