Nov 16
Here are some tips to creating low latency servers.
- Use low level TCP instead of any high level HTTP (applies to .NET RMI as well)
- Don’t use too descriptive language like XML unless constraint by requirements. This is a repeated pattern in mobile development (iPhone development included) .
- If absolutely have to use HTTP, use 1.1 keep alive to avoid closing and opening http connections.
- Rule of thumb - open/close connection is very very expensive in terms of creating sockets with OS.
- Don’t do a lot of I/O - For logging or data collection, have another thread to buffer the write every interval.
- Again, Don’t use I/O. Load data into memory at all if possible or cache the data. I’ve worked in Realtime systems, and even for dot com companies, we always load lookup & hash tables to memory, sometimes a few MB of memory or even a few GIGS of memory. Make sure the system have plenty of memory otherwise your server will thrash as it tries to page in and out of disk.
- Please don’t query database ( I/O !! ) . If SLA is 5 ms or sometimes in microsecond, it is not realistic to query against database no matter how fast it is. Straight list search is decent, but Hash with O(1) is even better.
Nov 16
Minimize memory allocation, best not to allocate any memory in queries unless absolutely necessary.
- Allocate memory buffers ahead of time before going into the Query.
- Use Object Pool
- Use Thread Pool
- Use Thread specific storage
- Use buffers.
- Turn off RTTI on the compiler. Type information can be VERY expensive.
- Turn on optimization on the computer.
- Inline functions.
- Avoid too much level of abstraction. This makes it slower for code to transverse your hierarchy.
Nov 12
Here’s a quick code to check the sizes in your OS:
#include "stdio.h"
int main(){
printf("char = %i bytes\n",sizeof(char));
printf("short = %i bytes\n",sizeof(short));
printf("int = %i bytes\n",sizeof(int));
printf("long = %i bytes\n",sizeof(long));
printf("long long = %i bytes\n",sizeof(long long));
printf("float = %i bytes\n",sizeof(float));
printf("double = %i bytes\n",sizeof(double));
return 0;
}
Here’s the results:
Output:
char = 1 bytes
short = 2 bytes
int = 4 bytes
long = 4 bytes
long long = 8 bytes
float = 4 bytes
double = 8 bytes
It appears that float is only 32 bit, hence single precision floating point, and double is 64 bit, hence double precision floating point. It be can dangerous to use floating point in financial calculation because it can cause inaccuracy. I did not believe at first until I saw this great example w/ the code to prove that inaccuracy will happen eventually.
References:
http://virtuallyshocking.com/2008/01/14/float-vs-double/
Wikipedia - Double precision
Nov 11
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!