2017-05-26 04:48:44 +08:00
|
|
|
/*
|
2020-10-30 11:42:23 +08:00
|
|
|
* AsyncFileS3BlobStore.actor.cpp
|
2017-05-26 04:48:44 +08:00
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2020-10-30 11:42:23 +08:00
|
|
|
#include "fdbclient/AsyncFileS3BlobStore.actor.h"
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbrpc/AsyncFileReadAhead.actor.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#include "flow/UnitTest.h"
|
2019-02-18 06:55:47 +08:00
|
|
|
#include "flow/actorcompiler.h" // has to be last include
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2020-10-30 11:42:23 +08:00
|
|
|
Future<int64_t> AsyncFileS3BlobStoreRead::size() const {
|
2021-03-11 02:06:03 +08:00
|
|
|
if (!m_size.isValid())
|
|
|
|
m_size = m_bstore->objectSize(m_bucket, m_object);
|
2017-05-26 04:48:44 +08:00
|
|
|
return m_size;
|
|
|
|
}
|
|
|
|
|
2020-10-30 11:42:23 +08:00
|
|
|
Future<int> AsyncFileS3BlobStoreRead::read(void* data, int length, int64_t offset) {
|
2017-05-26 04:48:44 +08:00
|
|
|
return m_bstore->readObject(m_bucket, m_object, data, length, offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTOR Future<Void> sendStuff(int id, Reference<IRateControl> t, int bytes) {
|
|
|
|
printf("Starting fake sender %d which will send send %d bytes.\n", id, bytes);
|
|
|
|
state double ts = timer();
|
|
|
|
state int total = 0;
|
2020-10-30 11:42:23 +08:00
|
|
|
while (total < bytes) {
|
|
|
|
state int r = std::min<int>(deterministicRandom()->randomInt(0, 1000), bytes - total);
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(t->getAllowance(r));
|
2017-05-26 04:48:44 +08:00
|
|
|
total += r;
|
|
|
|
}
|
|
|
|
double dur = timer() - ts;
|
2020-10-30 11:42:23 +08:00
|
|
|
printf("Sender %d: Sent %d in %fs, %f/s\n", id, total, dur, total / dur);
|
2017-05-26 04:48:44 +08:00
|
|
|
return Void();
|
|
|
|
}
|
|
|
|
|
2018-10-06 13:09:58 +08:00
|
|
|
TEST_CASE("/backup/throttling") {
|
2017-05-26 04:48:44 +08:00
|
|
|
// Test will not work in simulation.
|
2021-03-11 02:06:03 +08:00
|
|
|
if (g_network->isSimulated())
|
|
|
|
return Void();
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
state int limit = 100000;
|
|
|
|
state Reference<IRateControl> t(new SpeedLimit(limit, 1));
|
|
|
|
|
|
|
|
state int id = 1;
|
|
|
|
std::vector<Future<Void>> f;
|
|
|
|
state double ts = timer();
|
|
|
|
state int total = 0;
|
|
|
|
int s;
|
|
|
|
s = 500000;
|
2020-10-30 11:42:23 +08:00
|
|
|
f.push_back(sendStuff(id++, t, s));
|
|
|
|
total += s;
|
|
|
|
f.push_back(sendStuff(id++, t, s));
|
|
|
|
total += s;
|
2017-05-26 04:48:44 +08:00
|
|
|
s = 50000;
|
2020-10-30 11:42:23 +08:00
|
|
|
f.push_back(sendStuff(id++, t, s));
|
|
|
|
total += s;
|
|
|
|
f.push_back(sendStuff(id++, t, s));
|
|
|
|
total += s;
|
2017-05-26 04:48:44 +08:00
|
|
|
s = 5000;
|
2020-10-30 11:42:23 +08:00
|
|
|
f.push_back(sendStuff(id++, t, s));
|
|
|
|
total += s;
|
2017-05-26 04:48:44 +08:00
|
|
|
|
2018-08-11 04:57:10 +08:00
|
|
|
wait(waitForAll(f));
|
2017-05-26 04:48:44 +08:00
|
|
|
double dur = timer() - ts;
|
|
|
|
int speed = int(total / dur);
|
|
|
|
printf("Speed limit was %d, measured speed was %d\n", limit, speed);
|
|
|
|
ASSERT(abs(speed - limit) / limit < .01);
|
|
|
|
|
|
|
|
return Void();
|
|
|
|
}
|