<div dir="ltr">Ahhh, cool. Well the db is mysql and sits on the same box so probably fine. Just don't really know.<div><br></div><div>I'll keep this in mind and apply if needed.</div><div>Thanks for all your help, amazing! </div>
<div>Keith</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 14, 2013 at 3:46 PM, Klaus Darilion <span dir="ltr"><<a href="mailto:klaus.mailinglists@pernau.at" target="_blank">klaus.mailinglists@pernau.at</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
On 14.10.2013 14:57, Keith wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Klaus, thank you for pointing me in the right direction with SIP trunks,<br>
got it working so thanks! Basically I did exactly what you said:<br>
<br>
- Dialled number<br>
- Match that number to a registered user (had to create a new table for<br>
that)<br>
- Lookup user<br>
- Replace dialled s@ with original number dialled<br>
<br>
Works like a charm, however, I have a question over speed and<br>
performance. As this is a SQL query and not held in memory is this SQL<br>
lookup doing to cause me problems? It's not a big query at the moment,<br>
but it could get quite big as I will need to map each number to a<br>
registered trunk.<br>
</blockquote>
<br></div></div>
It depends on your database. If the database is fast, this is usually not a problem. Many Kamailio users e.g. use the usrloc module without caching, thus every lookup() call requires a DB lookup. Also authentication is usually not cached, and requires a DB lookup for every SIP request (INVITE, REGISTER).<br>

<br>
Thus, if the DB is fast, you are fine.<br>
<br>
If the DB is slow or unreliable, then Kamailio is slow too. But usually you anyway need the DB for accounting and authentication - thus if the DB is not available quite often you do not want any calls to proceed (as you can not bill them).<br>

<br>
Anyway, if you are afraid of DB performance, or you have quite slow queries which usually return the same result, you can use caching using the htable module. See the readme. But a simple example (untested): e.g. you want to cache the DID-to-user mapping for 1 hour.<br>

<br>
modparam("htable", "htable", "dids=>size=10;autoexpire=<u></u>3600;")<br>
<br>
route {<br>
<br>
  ....<br>
  # incoming did is in $rU<br>
  # use the DID as hash key<br>
  $var(mapping) = $sht(a=>$rU);<br>
  if ( $var(mapping) ) {<br>
    xlog("Using cached mapping: $rU -> $var(mapping)");<br>
    $rU = $var(mapping);<br>
  } else {<br>
    # your code to load the mapping from DB into $var(mapping)<br>
    .....<br>
    xlog("Loaded mapping from DB: $rU -> $var(mapping)");<br>
    $rU = $var(mapping);<br>
    # put the mapping into the hash table<br>
    $sht(a=>$rU) = $var(mapping);<br>
  }<br>
  lookup(...);<br>
<br>
<br>
<br>
regards<span class="HOEnZb"><font color="#888888"><br>
Klaus<br>
</font></span></blockquote></div><br></div>