What is sphsf-amon? I will not explain it here. Let's go straight to the question.
The official API interfaces are too simple to migrate from PHP to C #. for developers who are not familiar with Sphinx, it takes a lot of time to understand how to call various methods, in addition, the connection pool is not used for network connections. This is indeed better for PHP under a single-process, single-threaded Web Server such as Nginx or lighttpd, however. NET program is not so pleasant.
On this premise, I decided to develop a Sphinx client class library by myself.
The Sphinx protocol is very simple, but it also implies some traps. For example, some problems found during interface testing today:
1. When filtering results by time (DateTime) or INTEGER (Int32), the following error is always reported: "invalid or truncated request". No result is found on the internet for half a day, you can only watch the Server Source Code by yourself (it is difficult to reach out to the party :-().
The code for filtering the analysis scope is found in the source code:
Code
Switch (tFilter. m_eType)
{
Case SPH_FILTER_RANGE:
TFilter. m_uMinValue = (iVer> = 0x114 )? TReq. GetUint64 (): tReq. GetDword ();
TFilter. m_uMaxValue = (iVer> = 0x114 )? TReq. GetUint64 (): tReq. GetDword ();
Break;
Case SPH_FILTER_FLOATRANGE:
TFilter. m_fMinValue = tReq. GetFloat ();
TFilter. m_fMaxValue = tReq. GetFloat ();
Break;
Case SPH_FILTER_VALUES:
{
Bool bRes = (iVer> = 0x114)
? TReq. GetQwords (tFilter. m_dValues, g_iMaxFilterValues, "invalid attribute set length % d (shocould be in 0 .. % d range )")
: TReq. GetDwords (tFilter. m_dValues, g_iMaxFilterValues, "invalid attribute set length % d (shocould be in 0 .. % d range )");
If (! BRes)
Return false;
}
Break;
Default:
TReq. SendErrorReply ("unknown filter type (type-id = % d)", tFilter. m_eType );
Return false;
}
In the past, when the client code version of the Sphinx server was higher than 0x114, the maximum and minimum values were read by an 8-byte long integer. The problem was found, convert all values for range filtering to Int64 before sending them to the server, and then write them into the stream. OK. The problem is solved.
2. Use a Socket instead of TcpClient --
During stress testing, the performance of Socket communication is significantly better than that of TcpClient. In the stress testing process, TcpClient often reports errors. Currently, no reason is found, work very well.
This class library is still being tested and may encounter other problems.