Problems encountered during Sphinx client API writing

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.