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 ();
});
}その結果、フレームワークを使用すると、簡単なソースコードを取得すると、OSからのCPUを消費するコンテキストスイッチを避け、少量の実行スレッドでCPUを効率的に利用します。
私たちの出版物やビデオから、userverの履歴と主要な機能について詳しく知ることができます。
詳細については、ドキュメントを参照してください。