Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,9 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

# Exclude specific folders for spfresh_async_benchmark branch
store_murren1m_linux/
store_murren1m_windows/
target_datasets/
.vscode/
15 changes: 15 additions & 0 deletions AnnService.docker.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Service]
ListenAddr=0.0.0.0
ListenPort=8000
ThreadNumber=8
SocketThreadNumber=8

[QueryConfig]
DefaultMaxResultNumber=10
DefaultSeparator=|

[Index]
List=MURREN

[Index_MURREN]
IndexFolder=/app/indices/murren
15 changes: 15 additions & 0 deletions AnnService.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Service]
ListenAddr=0.0.0.0
ListenPort=8000
ThreadNumber=8
SocketThreadNumber=8

[QueryConfig]
DefaultMaxResultNumber=10
DefaultSeparator=|

[Index]
List=MURREN

[Index_MURREN]
IndexFolder=C:\src\SPFRESH_ASYNC_IO\store_murren1m_windows
15 changes: 15 additions & 0 deletions AnnService/AnnService.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Service]
ListenAddr=0.0.0.0
ListenPort=8000
ThreadNumber=8
SocketThreadNumber=8

[QueryConfig]
DefaultMaxResultNumber=10
DefaultSeparator=|

[Index]
List=MURREN

[Index_MURREN]
IndexFolder=store_murren500k
6 changes: 4 additions & 2 deletions AnnService/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ install(TARGETS SPTAGLib SPTAGLibStatic
LIBRARY DESTINATION lib)

if (NOT LIBRARYONLY)
file(GLOB SERVER_HDR_FILES ${AnnService}/inc/Server/*.h ${AnnService}/inc/Socket/*.h)
file(GLOB SERVER_FILES ${AnnService}/src/Server/*.cpp ${AnnService}/src/Socket/*.cpp)
file(GLOB SERVER_HDR_FILES ${AnnService}/inc/Server/*.h ${AnnService}/inc/Socket/*.h ${AnnService}/inc/HTTP/*.h)
file(GLOB SERVER_FILES ${AnnService}/src/Server/*.cpp ${AnnService}/src/Socket/*.cpp ${AnnService}/src/HTTP/*.cpp)
# Remove test files from server build
list(REMOVE_ITEM SERVER_FILES ${AnnService}/src/HTTP/test_http.cpp)
add_executable (server ${SERVER_FILES} ${SERVER_HDR_FILES})
target_link_libraries(server ${Boost_LIBRARIES} SPTAGLibStatic)

Expand Down
2 changes: 2 additions & 0 deletions AnnService/Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<ClInclude Include="inc\Server\SearchService.h" />
<ClInclude Include="inc\Server\ServiceContext.h" />
<ClInclude Include="inc\Server\ServiceSettings.h" />
<ClInclude Include="inc\Server\InsertDeleteExecutor.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Server\main.cpp" />
Expand All @@ -131,6 +132,7 @@
<ClCompile Include="src\Server\SearchService.cpp" />
<ClCompile Include="src\Server\ServiceContext.cpp" />
<ClCompile Include="src\Server\ServiceSettings.cpp" />
<ClCompile Include="src\Server\InsertDeleteExecutor.cpp" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
Expand Down
2 changes: 2 additions & 0 deletions AnnService/SocketLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<ClInclude Include="inc\Socket\ResourceManager.h" />
<ClInclude Include="inc\Socket\Server.h" />
<ClInclude Include="inc\Socket\RemoteSearchQuery.h" />
<ClInclude Include="inc\Socket\RemoteInsertDeleteQuery.h" />
<ClInclude Include="inc\Socket\SimpleSerialization.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -110,6 +111,7 @@
<ClCompile Include="src\Socket\ConnectionManager.cpp" />
<ClCompile Include="src\Socket\Packet.cpp" />
<ClCompile Include="src\Socket\RemoteSearchQuery.cpp" />
<ClCompile Include="src\Socket\RemoteInsertDeleteQuery.cpp" />
<ClCompile Include="src\Socket\Server.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down
20 changes: 18 additions & 2 deletions AnnService/inc/Client/ClientWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "inc/Socket/Client.h"
#include "inc/Socket/RemoteSearchQuery.h"
#include "inc/Socket/RemoteInsertDeleteQuery.h"
#include "inc/Socket/ResourceManager.h"
#include "Options.h"

Expand All @@ -27,6 +28,7 @@ class ClientWrapper
{
public:
typedef std::function<void(Socket::RemoteSearchResult)> Callback;
typedef std::function<void(Socket::RemoteInsertDeleteResult)> InsertDeleteCallback;

ClientWrapper(const ClientOptions& p_options);

Expand All @@ -36,6 +38,14 @@ class ClientWrapper
Callback p_callback,
const ClientOptions& p_options);

void SendInsertAsync(const Socket::RemoteInsertQuery& p_query,
InsertDeleteCallback p_callback,
const ClientOptions& p_options);

void SendDeleteAsync(const Socket::RemoteDeleteQuery& p_query,
InsertDeleteCallback p_callback,
const ClientOptions& p_options);

void WaitAllFinished();

bool IsAvailable() const;
Expand All @@ -51,6 +61,10 @@ class ClientWrapper

void SearchResponseHanlder(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);

void InsertResponseHandler(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);

void DeleteResponseHandler(Socket::ConnectionID p_localConnectionID, Socket::Packet p_packet);

void HandleDeadConnection(Socket::ConnectionID p_cid);

private:
Expand All @@ -71,10 +85,12 @@ class ClientWrapper
std::atomic<std::uint32_t> m_spinCountOfConnection;

Socket::ResourceManager<Callback> m_callbackManager;

Socket::ResourceManager<InsertDeleteCallback> m_insertDeleteCallbackManager;
};


} // namespace Socket
} // namespace Client
} // namespace SPTAG

#endif // _SPTAG_CLIENT_OPTIONS_H_
#endif // _SPTAG_CLIENT_CLIENTWRAPPER_H_
112 changes: 112 additions & 0 deletions AnnService/inc/HTTP/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

#ifndef _SPTAG_HTTP_COMMON_H_
#define _SPTAG_HTTP_COMMON_H_

// Prevent Windows.h from defining macros that conflict with our code
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifdef DELETE
#undef DELETE
#endif
#endif

#include <cstdint>
#include <string>
#include <chrono>

namespace SPTAG {
namespace HTTP {

// HTTP specific connection ID type
using HTTPConnectionID = std::uint64_t;
constexpr HTTPConnectionID c_invalidHTTPConnectionID = 0;

// HTTP status codes we commonly use
enum class StatusCode : std::uint16_t {
OK = 200,
Created = 201,
Accepted = 202,
NoContent = 204,
BadRequest = 400,
Unauthorized = 401,
Forbidden = 403,
NotFound = 404,
MethodNotAllowed = 405,
RequestTimeout = 408,
TooManyRequests = 429,
InternalServerError = 500,
BadGateway = 502,
ServiceUnavailable = 503,
GatewayTimeout = 504
};

// Request method type
enum class Method : std::uint8_t {
HTTP_GET,
HTTP_POST,
HTTP_PUT,
HTTP_DELETE,
HTTP_HEAD,
HTTP_OPTIONS,
HTTP_PATCH
};

// Connection state
enum class ConnectionState : std::uint8_t {
Connecting,
Connected,
Closing,
Closed
};

// Performance metrics
struct RequestMetrics {
std::chrono::steady_clock::time_point startTime;
std::chrono::steady_clock::time_point endTime;
std::size_t bytesReceived{0};
std::size_t bytesSent{0};
StatusCode statusCode{StatusCode::OK};
std::string path;
Method method{Method::HTTP_GET};

std::chrono::milliseconds GetLatency() const {
return std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime);
}
};

// Helper functions
inline const char* MethodToString(Method m) {
switch (m) {
case Method::HTTP_GET: return "GET";
case Method::HTTP_POST: return "POST";
case Method::HTTP_PUT: return "PUT";
case Method::HTTP_DELETE: return "DELETE";
case Method::HTTP_HEAD: return "HEAD";
case Method::HTTP_OPTIONS: return "OPTIONS";
case Method::HTTP_PATCH: return "PATCH";
default: return "UNKNOWN";
}
}

inline Method StringToMethod(const std::string& s) {
if (s == "GET") return Method::HTTP_GET;
if (s == "POST") return Method::HTTP_POST;
if (s == "PUT") return Method::HTTP_PUT;
if (s == "DELETE") return Method::HTTP_DELETE;
if (s == "HEAD") return Method::HTTP_HEAD;
if (s == "OPTIONS") return Method::HTTP_OPTIONS;
if (s == "PATCH") return Method::HTTP_PATCH;
return Method::HTTP_GET;
}

} // namespace HTTP
} // namespace SPTAG

#endif // _SPTAG_HTTP_COMMON_H_
Loading