Reputation: 641
In the context of testing a web applications performance, I was wondering if anyone could point me to a set of code snippets that allow for testing my (Tcl-based) web server's behavior under various different memory-related circumstances.
Therefore, it would be great to have a short proc that allocate/use a predefined amount of memory, hold that for a predefined amount of time, and free it up later on again.
(I am thinking of something that allows me to invoke URLs like this using jMeter: http://example.com/alloc.tcl?memory=1GB&free-after=5s)
Upvotes: 0
Views: 109
Reputation: 5692
Have you just considered a small C application which takes two arguments, one for memory size (in K) and the other for a delay in releasing (in seconds)? At that point you simply need a calloc(), sleep() and free(). You can then use exec in your TCL code to kick it off.
Upvotes: 0
Reputation: 137627
Well, there's nothing specifically for that, but you can approximate it. In particular, strings have their length correspond pretty strongly to the number of bytes used to allocate them (provided you're using ASCII) and the space is deallocated pretty much immediately once it is no longer referenced.
# Allocate a big chunk of data
set data [string repeat x 1000000000]
# Delay in milliseconds
after 5000
# Release the storage; local variables are unset automatically when a procedure exits
unset data
Be aware that whether the memory gets returned to the OS is non-trivial, as it depends on the behaviour of the low-level system memory allocator. Also be aware that Tcl has an absolute limit on the size of a single memory object of 2GB (because of a known awkward bug), so it is better to allocate your gigabyte in many smaller pieces, like this:
for {set i 0; set data {}} {$i < 1000} {incr i} {
lappend data [string repeat x 1000000]
}
Take care to not convert $data
to a single string. Gigabyte-sized strings can ensue and you easily run the risk of hitting the object size limit. So long as you just unset data
some time later, it will all work fine.
Upvotes: 1