SlashDB在长URL上返回502

时间:2018-03-09 01:30:36

标签: rest slashdb

我正在使用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

这是URL(大数据被截断):

/ 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);

任何人都能放弃任何光明吗?

1 个答案:

答案 0 :(得分: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..."
}'