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。
您可以从我们的出版物和视频中了解更多有关历史记录和关键功能的信息。
有关更多信息,请参见文档。