【问题标题】:SlashDB returns 502 on long URLSlashDB 在长 URL 上返回 502
【发布时间】:2018-08-17 12:34:14
【问题描述】:

我正在使用 SlashDB 在 MySQL 后端上分层 REST 接口。大多数情况下,我通过“SQL Pass-thru”功能定义查询。我们正在使用这个系统来记录来自各个测试站的测试数据。

将测试数据发送到数据库时,一旦 URL 超过一定长度(大约 2K 的数据),SlashDB 似乎会阻塞。返回的错误是“502”,这很奇怪,因为 URI 太长通常会返回“414”。当我直接在MySQL中尝试查询时,没有问题。

这是表定义:

CREATE TABLE `test_result` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `test_instance_id` bigint(20) unsigned NOT NULL,
  `test_instance_test_station_id` varchar(15) NOT NULL,
  `test_instance_unit_sn` varchar(30) NOT NULL,
  `test_instance_contact_address_id` int(2) NOT NULL,
  `testStep` varchar(45) DEFAULT NULL,
  `testData` blob,
  `externalDataLink` text,
  PRIMARY KEY (`id`),
  KEY `fk_test_result_test_instance1_idx` (`test_instance_id`,`test_instance_test_station_id`,`test_instance_unit_sn`,`test_instance_contact_address_id`),
  CONSTRAINT `fk_test_result_test_instance1` FOREIGN KEY (`test_instance_id`, `test_instance_test_station_id`, `test_instance_unit_sn`, `test_instance_contact_address_id`) REFERENCES `test_instance` (`id`, `test_station_id`, `unit_sn`, `contact_address_id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8

这是网址(大数据被截断):

/post-test-result/testId/116/locationId/99/stationId/BO-01/sn/991807000003/stepName/test2/testData/[这里有2K的数据]/dataUrl/bye2.json?limit= 29

通过“SQL Pass-thru”定义的查询:

插入 test_result(test_instance_id、test_instance_contact_address_id、test_instance_test_station_id、test_instance_unit_sn、testStep、testData、externalDataLink)值 (:testId, :locationId, :stationId, :sn, :stepName, :testData, :dataUrl);

有人能解释一下吗?

【问题讨论】:

  • 澄清一下,是 testData 参数的值使 URL 变长了?
  • 正确! testDats 参数使 URL 变长。

标签: rest slashdb


【解决方案1】:

尝试更新/etc/nginx/nginx.conf文件中的uwsgi缓冲区值

server {
    uwsgi_buffer_size 8k;
    uwsgi_buffers  4 8k;
    uwsgi_busy_buffers_size 16k;

# ... #

/etc/slashdb/slashdb.ini 文件,在[uwsgi] 部分的末尾添加buffer-size = 32768。 uwsgi 部分应如下所示:

# uWSGI config for service scriptm starts uWSGI as a daemon
[uwsgi]
socket = 127.0.0.1:8001
virtualenv = /opt/slashdb
daemonize = /var/log/slashdb/uwsgi.log
log-maxsize = 20971520
master = true
enable-threads = true
single-interpreter = true
lazy-apps = true
processes = 1
threads = 2
paste = config:%p
paste-logger = %p
buffer-size = 32768

然后重启服务:

sudo service slashdb stop
sudo service slashdb start
sudo service nginx restart

BTW SlashDB 目前不反映 BLOB 类型,但如果您将 testData 列类型更改为 text,那么您将能够在 Data Discovery 中使用更适合您的用例的 POST 方法。

使用 curl 会是

curl -v 'http://slashdb.reshareu/db/testing/test_result.json' \
-X POST \
-H 'apikey: your-api-key-here' \
-H 'content-type: application/json' \
--data '{
  "test_instance_test_station_id": "BO-01",
  "test_instance_contact_address_id": 99,
  "test_instance_unit_sn": "991807000003",
  "testStep": "test2",
  "externalDataLink": "bye2",
  "test_instance_id": 116,
  "testData": "Very long yata, yata, yata..."
}'

【讨论】:

  • 不幸的是,uwsgi 缓冲区值不起作用。但是,我也注意到一些奇怪的事情。在我的 SlashDB 安装中,uwsgi 没有运行。 $ sudo systemctl status uwsgi ● uwsgi.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)
  • 我已经在我的环境中重现了您的错误。结束 uwsgi_buffer 大小适用于大约 3k 个字符长的 url。更改后是否重新加载了 nginx?要查看 SlashDB 是否正在运行,请尝试 ps uax | grep uwsgi 并查看该进程是否正在运行。顺便说一句,您是如何安装 SlashDB 脚本、系统包、docker 的?您使用的是哪个版本的 SlashDB?
  • 感谢您抽出宝贵时间帮助我。我按照网站上的规定将 SlashDB 安装为系统包。它是 0.9.53 版本。是的,我在更改配置文件后重新启动了 SlashDB 和 memcached。我什至尝试重新启动虚拟机。 ps uax | grep uwsgi 即使在 SlashDB 正在运行并响应时也出现空缺。顺便说一句,这个问题出现在我所有的开发机器上(我有 2 个)。
  • 好的,我忘了在 /etc/slashdb/slashdb.ini 中写关于 uwsgi 设置的更改。我已经更新了我的答案。
  • 如果 ps aux | grep uwsgi 没有返回任何东西,那么 SlashDB 就没有运行。访问主页时,您应该收到502 Bad Gateway。除非您设置了缓存,否则响应可能来自 nginx 缓存。` 还请查看 nginx 日志,它们位于 /var/log/nginx 中以了解 502 错误的实际原因。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-11-05
  • 1970-01-01
  • 2021-12-01
  • 2014-12-12
  • 2019-05-29
相关资源
最近更新 更多