userver
2.6
| 服務模板 | 開發 /綠色樹幹 | v2.0 | v1.0 |
|---|---|---|---|
| 核: | [➚] | [➚] | |
| PostgreSQL: | [➚] | [➚] | |
| GRPC+PostgreSQL: | [➚] | [➚] |
Userver是一個開源異步框架,具有豐富的抽象集,可快速,舒適地創建C ++微服務,服務和實用程序。
該框架為開發人員透明地解決了有效I/O交互的問題。通常會暫停執行線程的操作不會暫停。相反,線程處理其他請求和任務,並僅在保證立即執行操作時返回到操作的處理:
# include < userver/easy.hpp >
# include " schemas/key_value.hpp "
int main ( int argc, char * argv[]) {
using namespace userver ;
easy::HttpWith<easy::PgDep>(argc, argv)
// Handles multiple HTTP requests to `/kv` URL concurrently
. Get ( " /kv " , [](formats::json::Value request_json, const easy::PgDep& dep) {
// JSON parser and serializer are generated from JSON schema by userver
auto key = request_json. As <schemas::KeyRequest>(). key ;
// Asynchronous execution of the SQL query in transaction. Current thread
// handles other requests while the response from the DB is being received:
auto res = dep. pg (). Execute (
storages::postgres::ClusterHostType:: kSlave ,
// Query is converted into a prepared statement. Subsequent requests
// send only parameters in a binary form and meta information is
// discarded on the DB side, significantly saving network bandwidth.
" SELECT value FROM key_value_table WHERE key=$1 " , key
);
schemas::KeyValue response{key, res[ 0 ][ 0 ]. As <std::string>()};
return formats::json::ValueBuilder{response}. ExtractValue ();
});
}結果,使用該框架,您可以直接獲得源代碼,避免使用CPU耗費的上下文從OS開關,從而有效地使用少量執行線程使用CPU。
您可以從我們的出版物和視頻中了解更多有關歷史記錄和關鍵功能的信息。
有關更多信息,請參見文檔。