Welcome! Log In Create A New Profile

Advanced

Re: Test the OOM situation

Maxim Dounin
May 18, 2010 03:28PM
Hello!

On Tue, May 18, 2010 at 08:25:46PM +0400, Peter Leonov wrote:

> Hello devels,
>
> There is a module that requires a heavy testing in environment with
> low memory. Especialy it could be good to test how it goes if no
> more memory is available in the system.
>
> So the questions are: is there a way to test such a module without a
> virtual machines? and are there some tools which might be of help?

You may tune memory limit for a given process instead of using
virtual machine. Though this won't really help with testing nginx
modules as pool allocator will protect most of allocations from
seeing errors (while they still can happen with sligtly different
config).

Injecting random errors into allocation routines proven to be much
more usable. Just for completeness: attached trivial patch which
I used while searching for allocation error handling bugs in nginx
itself.

Maxim Dounin
diff --git a/src/core/ngx_palloc.c b/src/core/ngx_palloc.c
--- a/src/core/ngx_palloc.c
+++ b/src/core/ngx_palloc.c
@@ -117,6 +117,14 @@ ngx_palloc(ngx_pool_t *pool, size_t size
u_char *m;
ngx_pool_t *p;

+#if 1 /* XXX */
+ if (ngx_random() % 1000 == 1) {
+ ngx_log_error(NGX_LOG_EMERG, pool->log, 0,
+ "shit happens, failing allocation of %uz bytes", size);
+ return NULL;
+ }
+#endif
+
if (size <= pool->max) {

p = pool->current;
diff --git a/src/os/unix/ngx_alloc.c b/src/os/unix/ngx_alloc.c
--- a/src/os/unix/ngx_alloc.c
+++ b/src/os/unix/ngx_alloc.c
@@ -19,6 +19,14 @@ ngx_alloc(size_t size, ngx_log_t *log)
void *p;

p = malloc(size);
+
+#if 1 /* XXX */
+ if (p != NULL && ngx_random() % 100 == 1) {
+ free(p);
+ p = NULL;
+ }
+#endif
+
if (p == NULL) {
ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
"malloc() %uz bytes failed", size);
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Test the OOM situation

Peter Leonov 2227 May 18, 2010 12:26PM

Re: Test the OOM situation

Brian Pane 768 May 18, 2010 01:16PM

Re: Test the OOM situation

Peter Leonov 839 May 19, 2010 07:48AM

Re: Test the OOM situation

Maxim Dounin 778 May 18, 2010 03:28PM

Re: Test the OOM situation

Peter Leonov 778 May 19, 2010 08:02AM

Re: Test the OOM situation

Maxim Dounin 823 May 19, 2010 09:32AM

Re: Test the OOM situation

Peter Leonov 1063 May 19, 2010 05:26PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 71
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready