Shared Memory

OASIS utilizes a number of shared memory segments to facilitate rapid ad delivery and to cut down the number of queries made against the database.

Hourly Assignments

SHM ID: 0x4f415300 (OAS0)
Read by: oasisi.php
Written by: hourly_maint.php
Size: 500 KB

Variables are hashed into the shared memory segment based on section number.

Each variable is a hash keyed by dimensions (WxH)

Each hash value is an array of creatives of the correct dimensions currently assigned to the section.

The size needed for this segment is dependent on the number of sections you have and the number of creatives.

A good formula to use is 11 * (sections * creatives)) where sections is the number of sections that have active creatives assigned to them, and creatives is the total number of active creatives. This is overkill, unless you have all creatives assigned to all sections, but it gives you a good safety margin.

In testing, 1024 creatives (of 8 different dimensions), all assigned to 128 sections required 1.37 MB of storage. This, of course, is a worst case scenario -- it assumes that you have 1024 active creatives (pretty unlikely), and that each and every one of those creatives is assigned to every single section of your site (again, very unlikely with a large site).

In the Admin interface, click on "Hourly Assignments" to see the contents of this segment. At the bottom, you can see how much of the allocated space is being used. If you think you need more, you can adjust the ShmSizeHourlyAssignments preference value.

Hourly Targets

SHM ID: 0x4f415301 (OAS1)
Read by: oasisi.php
oasisc.php
Written by: hourly_maint.php
oasisi.php
oasisc.php
Size: 50 KB

Variables are hashed into the shared memory segment based on creative number.

Each variable is an array of the following values: (target, weight, remaining, clicks, media type)

It may seem a bit strange to use "remaining", since it often results in negative numbers, but this allows us to more quickly identify creatives that _need_ impressions during the hour. Any creative with a remaining value > 0 has to get impressions. If we kept an incrementing counter instead, we'd have to perform a subtraction of the delivered number from the target number to determine who needs impressions. This is a slight inefficiency. I will admit, however, that the optimization of using a decrementing counter may not even make a significant difference, given all the other calculations that are going on.

The size needed for this segment is proportional to the maximum number of active creatives you have at any one time. It requires approximately 64 bytes for each active creative. 50 KB would allow for 780 active creatives in the system on any given day.

Creative Content

SHM ID: 0x4f415302 (OAS2)
Read by: oasisi.php
Written by: daily_maint.php
Size: 4 MB

Variables are hashed into the shared memory segment based on creative number

Each variable is an array of the following values (Content, Redirect, MIMEType, Animated)

The amount of space required is equal to the number of active creatives * (Average Size + 85 Bytes). So if you expect your ad content to take up 15KB each, then you'll need a little bit more than 15 MB to hold 1000 active creatives. Keep in mind that creatives that use third-party ad delivery require considerably less storage.

In the Admin interface, click on "Creative Content" to see the contents of this segment. At the bottom, you can see how much of the allocated space is being used. If you think you need more, you can adjust the ShmSizeCreativeContent preference value.

Note for FreeBSD users:

In the FreeBSD default GENERIC kernel, there is maximum shared memory segment size of 4194304 (4MB).

If you want bigger ShmSizeCreativeContent, you must recompile kernel with this options:

options SHMMAXPGS=2049
options SHMMAX="(SHMMAXPGS*PAGE_SIZE+1)"

This sets maximum shared memory to 8MB. If you want 16MB, you must use 4097 and so on.

Creative Clickthrough

SHM ID: 0x4f415303 (OAS3)
Read by: oasisc.php
Written by: daily_maint.php
Size: 500 KB

Variables are hashed into the shared memory segment based on creative number

Each variable is a string containing the clickthrough URL for the creative.

The size required for this segment is proportional to the maximum number of active creatives. It is roughly equal to the number of active creatives * 276 Bytes

This is a worst-case number; it assumes that each active creative has a 255-character clickthrough URL (the largest that can be stored in the database table).

A 300 KB shared memory segment can therefore store well over 1000 active creatives.

In the Admin interface, click on "Creative Clickthrough" to see the contents of this segment. At the bottom, you can see how much of the allocated space is being used. If you think you need more, you can adjust the ShmSizeCreativeClickthroughs preference value.

Deliveries

The original design of OASIS called for a Deliveries shared memory segment, where we would record the creatives seen by each user for future clickthroughs. Unfortunately, PHP's shared memory manager is too primitive to handle the rapid insertion of many thousands of keys.

Instead, I've opted to use a MySQL heap table to store the delivery information. The insertions are reasonably fast, and having an indexed table allows for much faster lookups.